[Twisted-Python] thread pool question

Rutt, Benjamin Benjamin.Rutt at gs.com
Thu Mar 22 12:48:59 MDT 2007


From
http://twistedmatrix.com/projects/core/documentation/howto/threading.htm
l:

I copied the code below and ran it as:

	$ cat twisted-threadpool.py 
	#!/usr/bin/env python

	from twisted.internet import reactor

	def aSillyBlockingMethod(x):
	    import time
	    time.sleep(2)
	    print x

	# run method in thread
	reactor.callInThread(aSillyBlockingMethod, "2 seconds have
passed")

	$ ./twisted-threadpool.py 
	2 seconds have passed

But I note that the program never stops.  I infer that least one thread
is getting set as a non-daemon thread, according to python's thread
rules on program termination:

  `thread.setDaemon(daemonic)'
     Set the thread's daemon flag to the Boolean value DAEMONIC.  This
     must be called before `start()' is called.

     The initial value is inherited from the creating thread.

     The entire Python program exits when no active non-daemon threads
     are left.

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?

Thanks,
-- 
Benjamin Rutt


-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20070322/8defeae6/attachment.html>


More information about the Twisted-Python mailing list