<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tech Scribblings &#187; python</title>
	<atom:link href="http://tech.pedersen-live.com/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.pedersen-live.com</link>
	<description></description>
	<lastBuildDate>Tue, 10 Nov 2009 05:16:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Killing a thread in Python</title>
		<link>http://tech.pedersen-live.com/2009/01/killing-a-thread-in-python/</link>
		<comments>http://tech.pedersen-live.com/2009/01/killing-a-thread-in-python/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 16:45:43 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://tech.pedersen-live.com/?p=17</guid>
		<description><![CDATA[I have been searching for quite a while for information on how to kill a thread in Python and I finally found a great solution. I was just about to implement my own way of doing it but it is not as clean as this way (although killing threads is not clean in the first [...]]]></description>
			<content:encoded><![CDATA[<p>I have been searching for quite a while for information on how to kill a thread in Python and I finally found a great solution. I was just about to implement my own way of doing it but it is not as clean as this way (although killing threads is not clean in the first place).</p>
<p>My thought was to use threading.settrace() and set my own trace function for every thread that is started. That way every thread will have to pass through the trace function in oder to continue executing and it doesn&#8217;t matter where in the code it is at or going. In my trace function I was going to add an Event that it would wait on if I want to pause execution of the thread, or check something to make it through an execption to exit out of the thread.</p>
<p>I was in the process of searching for a way to find out if a thread died because of an Exception when I ran across a post here: <a href="http://www.dlevel.com/blogs/alex/20" target="_blank">http://www.dlevel.com/blogs/alex/20</a></p>
<p>What they have done is added a terminate() method to the Thread class in the threading library. This will throw a SystemExit exception and quitely terminate the thread. Just take the code and paste it into a new module and use that Thread class as opposed to the threading.Thread class.</p>
<p>I agree with what he says about using this. Obviously it is not very safe to do this but in some cases you really need a way to terminate a thread and if you are careful it can work out ok.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.pedersen-live.com/2009/01/killing-a-thread-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interesting Python Static Attributes</title>
		<link>http://tech.pedersen-live.com/2008/12/interesting-python-static-attributes/</link>
		<comments>http://tech.pedersen-live.com/2008/12/interesting-python-static-attributes/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 01:19:42 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://tech.pedersen-live.com/?p=14</guid>
		<description><![CDATA[So I was playing around with some code in Python today and was  curious about static members of a class (I guess that is what you would call it). I wanted to know if I set an attribute at the class level and change it, would all the instances see that change or if each [...]]]></description>
			<content:encoded><![CDATA[<p>So I was playing around with some code in Python today and was  curious about static members of a class (I guess that is what you would call it). I wanted to know if I set an attribute at the class level and change it, would all the instances see that change or if each instance is separate.</p>
<p>Here is some code I played with:</p>
<p><code><br />
&gt;&gt;&gt; class T:<br />
...     build_location = None<br />
...     def get_location(self):<br />
...               return self.build_location<br />
...<br />
&gt;&gt;&gt; t = T()<br />
&gt;&gt;&gt; print t.get_location()<br />
None<br />
&gt;&gt;&gt; T.build_location = "hello"<br />
&gt;&gt;&gt; print t.get_location()<br />
hello<br />
&gt;&gt;&gt; t.build_location = "there"<br />
&gt;&gt;&gt; print t.get_location()<br />
there<br />
&gt;&gt;&gt; print T.build_location<br />
hello<br />
&gt;&gt;&gt; T.build_location = "hello"<br />
&gt;&gt;&gt; print t.get_location()<br />
there<br />
&gt;&gt;&gt;</code></p>
<p>So, what I did was set an attribute on the class level that everyone can see without an instance of the class. When I create an instance it can see that attribute just like I can from just doing T.build_location. When I change the static variable then the instance sees that change as well (which is what I was hoping for).</p>
<p>Now, the interesting part is that if I use an instance of the class to change the variable, that variable becomes local to that instance as you can see above when I printed the class&#8217;s T.build_location. Now I tried to set the class level attribute back to &#8220;hello&#8221; and that works but now it does not change what the instance sees!</p>
<p>This is not any earth shattering news but I thought it was interesting when I saw it.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.pedersen-live.com/2008/12/interesting-python-static-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
