<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>thread pool question</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">From </FONT><A HREF="http://twistedmatrix.com/projects/core/documentation/howto/threading.html"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://twistedmatrix.com/projects/core/documentation/howto/threading.html</FONT></U></A><FONT SIZE=2 FACE="Arial">:</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I copied the code below and ran it as:</FONT>
</P>
<UL>
<P><FONT SIZE=2 FACE="Arial">$ cat twisted-threadpool.py </FONT>

<BR><FONT SIZE=2 FACE="Arial">#!/usr/bin/env python</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">from twisted.internet import reactor</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">def aSillyBlockingMethod(x):</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; import time</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; time.sleep(2)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; print x</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial"># run method in thread</FONT>

<BR><FONT SIZE=2 FACE="Arial">reactor.callInThread(aSillyBlockingMethod, &quot;2 seconds have passed&quot;)</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">$ ./twisted-threadpool.py </FONT>

<BR><FONT SIZE=2 FACE="Arial">2 seconds have passed</FONT>
</P>
</UL>
<P><FONT SIZE=2 FACE="Arial">But I note that the program never stops.&nbsp; I infer that least one thread is getting set as a non-daemon thread, according to python's thread rules on program termination:</FONT></P>

<P><FONT SIZE=2 FACE="Arial">&nbsp; `thread.setDaemon(daemonic)'</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp; Set the thread's daemon flag to the Boolean value DAEMONIC.&nbsp; This</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp; must be called before `start()' is called.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp; The initial value is inherited from the creating thread.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp; The entire Python program exits when no active non-daemon threads</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp; are left.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Is there a way to set this program up such that the program will exit when all of the threads registered via callInThread, and the main thread, have exited?</FONT></P>

<P><FONT SIZE=2 FACE="Arial">Thanks,</FONT>

<BR><FONT SIZE=2 FACE="Arial">-- </FONT>

<BR><FONT SIZE=2 FACE="Arial">Benjamin Rutt</FONT>
</P>
<BR>

</BODY>
</HTML>