[Twisted-Python] twisted and threading

Christopher Armstrong radeex at gmail.com
Wed Aug 18 00:02:03 EDT 2004

On Tue, 17 Aug 2004 23:18:59 -0400, Jp Calderone <exarkun at divmod.com> wrote:
> twisted-10152003 at atlas.lcs.mit.edu wrote:
> > Ah, but that doesn't work.  As I stated the c library (not mine) calls
> > potentially block forever (or at least longer than I want to wait to
> > shutdown the twisted server).  The thread created by deferTothread may
> > never complete which makes shutting down the server gracefully
> > impossible (or so I thought?).
> >
>    There is no portable way to terminate a thread without its
> assistance.  Python supports no API for this - save one, the
> ridiculously named "setDaemon" Thread method.  Twisted doesn't expose
> this, nor call it internally, as it can lead to segfaults.
>    Perhaps this should be parameterizable (defaulting to the current
> behavior, of course), so that poorly behaved libraries can be dealt with?
>    Alternatively, since daemonized threads might lead to this anyway,
> perhaps you should just add a shutdown event os.kill(os.getpid(), 9)
> <wwinkink>.

Well, since he only wants to murder the thread at shutdown, a regular
"thread killing" API isn't necessary, just a way to have the thread
not block shutting down, by dying. Your os.kill suggestion is along
the lines of what I was thinking of, except maybe there's a less
horrible option :)

 Twisted | Christopher Armstrong: International Man of Twistery
  Radix  |          Release Manager,  Twisted Project
---------+            http://radix.twistedmatrix.com

More information about the Twisted-Python mailing list