[Twisted-Python] Minor question wrt threading pools
I'm sitting down to move more of our application into Twisted and have come across a minor question that I'm thinking would be a good addition to the threading howto. In particular, starting a thread-pool seems to start the threads as non-daemon threads, so that on completion of the main reactor loop the threads are still hanging around (AFAICS, anyway, the app sits hung waiting for the background threads to complete). It would be useful to know: * How to start threads in the threading pool as daemon threads (i.e. will exit when all non-daemon threads exit) * How to force an exit of all threads o How to access the currently active thread-pool (I assume the documented ThreadPool.stop method is what needs to be called, but how to get the ThreadPool object isn't documented AFAICS). Anyway, it's not a show-stopper, I can just kill the app manually after each test run, still, would love to have an answer. Have fun, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/
Argh, as always, discovered the solution seconds after sending the email: ThreadPool is available as an (optional) attribute of reactor "threadpool". Calling stop() allows the exit. Still don't know how to make the threads daemon by default, but that's not an issue at the moment. Sorry for the wasted bandwidth, Mike Mike C. Fletcher wrote: ...
* How to start threads in the threading pool as daemon threads (i.e. will exit when all non-daemon threads exit) * How to force an exit of all threads o How to access the currently active thread-pool (I assume the documented ThreadPool.stop method is what needs to be called, but how to get the ThreadPool object isn't documented AFAICS).
...
On Fri, 2004-04-16 at 23:26, Mike C. Fletcher wrote:
* How to start threads in the threading pool as daemon threads (i.e. will exit when all non-daemon threads exit)
I've seen python core dump when this is done (python 2.0 IIRC, but I'm still *very* wary of doing it). I wouldn't if I were you :)
* How to force an exit of all threads
They exit automatically when program ends, i.e. you do reactor.stop() - unless they are doing something, in which case they will exit when they next try to read next task from queue. Your problem may be because you are doing tests and thus reactor.stop() is neveer called and it thus never shuts down the threadpool for you. -- Itamar Shtull-Trauring http://itamarst.org Looking for a job -- http://itamarst.org/resume.html
participants (2)
-
Itamar Shtull-Trauring
-
Mike C. Fletcher