<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Threading in Django</title>
	<atom:link href="http://www.artfulcode.net/articles/threading-django/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artfulcode.net/articles/threading-django/</link>
	<description>Resources and tips for dynamic, interactive languages.</description>
	<lastBuildDate>Mon, 23 Jan 2012 14:26:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: walty</title>
		<link>http://www.artfulcode.net/articles/threading-django/comment-page-1/#comment-2114</link>
		<dc:creator>walty</dc:creator>
		<pubDate>Wed, 29 Sep 2010 00:48:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/threading-django/#comment-2114</guid>
		<description>&lt;blockquote cite=&quot;#commentbody-2079&quot;&gt;
&lt;strong&gt;&lt;a href=&quot;#comment-2079&quot; rel=&quot;nofollow&quot;&gt;Andrej Primc&lt;/a&gt; :&lt;/strong&gt;
You shouldn’t  set thread.daemon = True. If your main thread exits, the daemon thread will die. If it works for you, it’s because Apache doesn’t kill its processes often. :)
You should either use a normal thread or a queue.
&lt;code&gt;
import threading
import Queue
import atexit&lt;/code&gt;&lt;code&gt;
def _worker():
while True:
func, args, kwargs = _queue.get()
try:
func(*args, **kwargs)
except:
pass# bork or ignore here; ignore for now
finally:
_queue.task_done()# so we can join at exit
def postpone(func):
def decorator(*args, **kwargs):
_queue.put((func, args, kwargs))
return decorator
_queue = Queue.Queue()
_thread = threading.Thread(target = _worker)# one is enough; it&#039;s postponed after all
_thread.daemon = True# so we can exit
_thread.start()
def _cleanup():
_queue.join()# so we don&#039;t exit too soon
&lt;/code&gt;&lt;code&gt;atexit.register(_cleanup)
&lt;/code&gt;
Use it like this
&lt;code&gt;
@postpone
def foo():
pass # do your stuff here
&lt;/code&gt;
&lt;/blockquote&gt;


andre primc,


your code works great! 

it&#039;s too bad that the post here does not support code indentation.

may be u try to put it somewhere in google code?</description>
		<content:encoded><![CDATA[<blockquote cite="#commentbody-2079"><p>
<strong><a href="#comment-2079" rel="nofollow">Andrej Primc</a> :</strong><br />
You shouldn’t  set thread.daemon = True. If your main thread exits, the daemon thread will die. If it works for you, it’s because Apache doesn’t kill its processes often. :)<br />
You should either use a normal thread or a queue.<br />
<code><br />
import threading<br />
import Queue<br />
import atexit</code><code><br />
def _worker():<br />
while True:<br />
func, args, kwargs = _queue.get()<br />
try:<br />
func(*args, **kwargs)<br />
except:<br />
pass# bork or ignore here; ignore for now<br />
finally:<br />
_queue.task_done()# so we can join at exit<br />
def postpone(func):<br />
def decorator(*args, **kwargs):<br />
_queue.put((func, args, kwargs))<br />
return decorator<br />
_queue = Queue.Queue()<br />
_thread = threading.Thread(target = _worker)# one is enough; it's postponed after all<br />
_thread.daemon = True# so we can exit<br />
_thread.start()<br />
def _cleanup():<br />
_queue.join()# so we don't exit too soon<br />
</code><code>atexit.register(_cleanup)<br />
</code><br />
Use it like this<br />
<code><br />
@postpone<br />
def foo():<br />
pass # do your stuff here<br />
</code>
</p></blockquote>
<p>andre primc,</p>
<p>your code works great! </p>
<p>it&#8217;s too bad that the post here does not support code indentation.</p>
<p>may be u try to put it somewhere in google code?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrej Primc</title>
		<link>http://www.artfulcode.net/articles/threading-django/comment-page-1/#comment-2079</link>
		<dc:creator>Andrej Primc</dc:creator>
		<pubDate>Wed, 30 Jun 2010 19:56:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/threading-django/#comment-2079</guid>
		<description>You shouldn&#039;t  set thread.daemon = True. If your main thread exits, the daemon thread will die. If it works for you, it&#039;s because Apache doesn&#039;t kill its processes often. :)

You should either use a normal thread or a queue.

&lt;code&gt;
import threading
import Queue
import atexit


def _worker():
	while True:
		func, args, kwargs = _queue.get()
		try:
			func(*args, **kwargs)
		except:
			pass	# bork or ignore here; ignore for now
		finally:
			_queue.task_done()	# so we can join at exit


def postpone(func):
	def decorator(*args, **kwargs):
		_queue.put((func, args, kwargs))
	return decorator


_queue = Queue.Queue()
_thread = threading.Thread(target = _worker)	# one is enough; it&#039;s postponed after all
_thread.daemon = True	# so we can exit
_thread.start()


def _cleanup():
	_queue.join()	# so we don&#039;t exit too soon

atexit.register(_cleanup)
&lt;/code&gt;

Use it like this

&lt;code&gt;
@postpone
def foo():
	pass # do your stuff here
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>You shouldn&#8217;t  set thread.daemon = True. If your main thread exits, the daemon thread will die. If it works for you, it&#8217;s because Apache doesn&#8217;t kill its processes often. :)</p>
<p>You should either use a normal thread or a queue.</p>
<p><code><br />
import threading<br />
import Queue<br />
import atexit</p>
<p>def _worker():<br />
	while True:<br />
		func, args, kwargs = _queue.get()<br />
		try:<br />
			func(*args, **kwargs)<br />
		except:<br />
			pass	# bork or ignore here; ignore for now<br />
		finally:<br />
			_queue.task_done()	# so we can join at exit</p>
<p>def postpone(func):<br />
	def decorator(*args, **kwargs):<br />
		_queue.put((func, args, kwargs))<br />
	return decorator</p>
<p>_queue = Queue.Queue()<br />
_thread = threading.Thread(target = _worker)	# one is enough; it's postponed after all<br />
_thread.daemon = True	# so we can exit<br />
_thread.start()</p>
<p>def _cleanup():<br />
	_queue.join()	# so we don't exit too soon</p>
<p>atexit.register(_cleanup)<br />
</code></p>
<p>Use it like this</p>
<p><code><br />
@postpone<br />
def foo():<br />
	pass # do your stuff here<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RawNawpairm</title>
		<link>http://www.artfulcode.net/articles/threading-django/comment-page-1/#comment-1979</link>
		<dc:creator>RawNawpairm</dc:creator>
		<pubDate>Fri, 01 Jan 2010 20:01:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/threading-django/#comment-1979</guid>
		<description>In my program I need to select multiple bytes, I have the first and last byte being 0x18 and 0x28. I&#039;m editing a txt file. I have it so whatever I put in is replaced. So I have myfile.seekg ( hexvalues = (0x18, 0x19, 0x20, etc.) You get the point. I want to just put in 0x18 and 0x28 and it gets everything in the middle. Im using fstream

_____________
&lt;a href=&quot;http://darmowetapety24.blogspot.com&quot; rel=&quot;nofollow&quot;&gt;Darmowe tapety&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>In my program I need to select multiple bytes, I have the first and last byte being 0&#215;18 and 0&#215;28. I&#8217;m editing a txt file. I have it so whatever I put in is replaced. So I have myfile.seekg ( hexvalues = (0&#215;18, 0&#215;19, 0&#215;20, etc.) You get the point. I want to just put in 0&#215;18 and 0&#215;28 and it gets everything in the middle. Im using fstream</p>
<p>_____________<br />
<a href="http://darmowetapety24.blogspot.com" rel="nofollow">Darmowe tapety</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Apache, processos, threads e django &#171; Enrico Batista da Luz</title>
		<link>http://www.artfulcode.net/articles/threading-django/comment-page-1/#comment-1919</link>
		<dc:creator>Apache, processos, threads e django &#171; Enrico Batista da Luz</dc:creator>
		<pubDate>Tue, 29 Sep 2009 12:19:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/threading-django/#comment-1919</guid>
		<description>[...] Threading in Django      Categoriasdjango, tech Tags:apache, django, process, thread       Comentários (0) Trackbacks (0) Deixe um comentário Trackback [...]</description>
		<content:encoded><![CDATA[<p>[...] Threading in Django      Categoriasdjango, tech Tags:apache, django, process, thread       Comentários (0) Trackbacks (0) Deixe um comentário Trackback [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: t2y</title>
		<link>http://www.artfulcode.net/articles/threading-django/comment-page-1/#comment-1917</link>
		<dc:creator>t2y</dc:creator>
		<pubDate>Sun, 27 Sep 2009 23:28:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/threading-django/#comment-1917</guid>
		<description>Hi, your article is just what I have been looking for.
I translated into Japanese in my site since it&#039;s great.
Thank you for good article!</description>
		<content:encoded><![CDATA[<p>Hi, your article is just what I have been looking for.<br />
I translated into Japanese in my site since it&#8217;s great.<br />
Thank you for good article!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: forest book</title>
		<link>http://www.artfulcode.net/articles/threading-django/comment-page-1/#comment-1916</link>
		<dc:creator>forest book</dc:creator>
		<pubDate>Sun, 27 Sep 2009 23:22:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/threading-django/#comment-1916</guid>
		<description>&lt;strong&gt;[django][python][translate]Django におけるスレッド...&lt;/strong&gt;

 Threading in Django &#124; Artful Code 本稿は上記リンク元の和訳になります 転載ミス、誤訳等については適宜修正します web 開発で利便性の高いスレッドの使用方法は珍しく、特に Python のグローバルインタープリタロックと共に使用するのは稀です。これに対して、幾つか注目...</description>
		<content:encoded><![CDATA[<p><strong>[django][python][translate]Django におけるスレッド&#8230;</strong></p>
<p> Threading in Django | Artful Code 本稿は上記リンク元の和訳になります 転載ミス、誤訳等については適宜修正します web 開発で利便性の高いスレッドの使用方法は珍しく、特に Python のグローバルインタープリタロックと共に使用するのは稀です。これに対して、幾つか注目&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert</title>
		<link>http://www.artfulcode.net/articles/threading-django/comment-page-1/#comment-1141</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Mon, 25 May 2009 15:07:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/threading-django/#comment-1141</guid>
		<description>Hi, I found your article useful, but also I found some errors ;) (from -&gt; from_, kwargs={&#039;fail_silently&#039;=True} -&gt; kwargs={&#039;fail_silently&#039;:True}). I made function similar to django.core.mail.send_mail:

&lt;code&gt;
import threading

def async_send_mail(subject, message, from_, recipients):
    &quot;&quot;&quot; 
    based on: 
        http://www.artfulcode.net/articles/threading-django/
    returns true allways
    &quot;&quot;&quot;
    from django.core.mail import send_mail

    # Create a new thread in Daemon mode to send message
    t = threading.Thread(target=send_mail,
                         args=[subject, message, from_, recipients],
                         kwargs={&#039;fail_silently&#039;:True})
    t.setDaemon(True)
    t.start()
    return True
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Hi, I found your article useful, but also I found some errors ;) (from -&gt; from_, kwargs={&#8216;fail_silently&#8217;=True} -&gt; kwargs={&#8216;fail_silently&#8217;:True}). I made function similar to django.core.mail.send_mail:</p>
<p><code><br />
import threading</p>
<p>def async_send_mail(subject, message, from_, recipients):<br />
    """<br />
    based on:<br />
        <a href="http://www.artfulcode.net/articles/threading-django/" rel="nofollow">http://www.artfulcode.net/articles/threading-django/</a><br />
    returns true allways<br />
    """<br />
    from django.core.mail import send_mail</p>
<p>    # Create a new thread in Daemon mode to send message<br />
    t = threading.Thread(target=send_mail,<br />
                         args=[subject, message, from_, recipients],<br />
                         kwargs={'fail_silently':True})<br />
    t.setDaemon(True)<br />
    t.start()<br />
    return True<br />
</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>

