[Twisted-Python] A problem with very long blocking thread in Twisted

Hi, fellow programmers. I have a problem with very long blocking thread(may not be finished) in Twisted. from socket import *
The process follows the below timeline:
Now main loop |>--------------------X thread | >--------------------------------------------... long time later ...---X ^ [Ctrl]+C Ideal main loop |>--------------------X thread | >-------------------X ^ [Ctrl]+C To solve this problem, I'd like to set threads as daemon. So that all related threads are terminated when main loop is interrupted. Any idea on this problem will be appreciated. ––––––––––––––––––––––––––– * Heungsub Lee sublee Mobile: +82-10-3215-2380 Site: http://subl.ee/ GitHub: http://github.com/sublee *

On Wed, Aug 10, 2011 at 2:49 PM, Heungsub Lee <h@subl.ee> wrote:
Hi Heungsub, Two options as far I as I can see: 1. Instead of having a blocking wait(), perhaps have it wait with a timeout? 2. Why don't you check out txAMQP, if you're doing amqp stuff - it has native integration into Twisted. http://pypi.python.org/pypi/txAMQP Keep in mind that if you set the thread as a daemon thread, the thread isn't actually "killed", there just isn't a join() called, so it gets claimed by the OS. This may be no different to what you want, but it's useful to keep it in mind. Reza -- Reza Lotun mobile: +44 (0)7521 310 763 email: rlotun@gmail.com work: rlotun@twitter.com @rlotun

On Wed, Aug 10, 2011 at 15:35, Itamar Turner-Trauring <itamar@itamarst.org> wrote:
When the choice is between aborting a thread and potentially dumping core, and not exiting, I'll take dumping core. In order to implement this in twisted, you need to subclass ThreadPool and override the method that creates the Thread object, or alternatively, don't use reactor.callInThread(). If you can substitute a threadpool for txAMPQ then that will probably be the cleanest way. Stephen.

On Wed, Aug 10, 2011 at 2:49 PM, Heungsub Lee <h@subl.ee> wrote:
Hi Heungsub, Two options as far I as I can see: 1. Instead of having a blocking wait(), perhaps have it wait with a timeout? 2. Why don't you check out txAMQP, if you're doing amqp stuff - it has native integration into Twisted. http://pypi.python.org/pypi/txAMQP Keep in mind that if you set the thread as a daemon thread, the thread isn't actually "killed", there just isn't a join() called, so it gets claimed by the OS. This may be no different to what you want, but it's useful to keep it in mind. Reza -- Reza Lotun mobile: +44 (0)7521 310 763 email: rlotun@gmail.com work: rlotun@twitter.com @rlotun

On Wed, Aug 10, 2011 at 15:35, Itamar Turner-Trauring <itamar@itamarst.org> wrote:
When the choice is between aborting a thread and potentially dumping core, and not exiting, I'll take dumping core. In order to implement this in twisted, you need to subclass ThreadPool and override the method that creates the Thread object, or alternatively, don't use reactor.callInThread(). If you can substitute a threadpool for txAMPQ then that will probably be the cleanest way. Stephen.
participants (4)
-
Heungsub Lee
-
Itamar Turner-Trauring
-
Reza Lotun
-
Thorne, Stephen