[Twisted-Python] Re: twisted and threading
db3l at fitlinxx.com
Wed Aug 18 16:20:37 MDT 2004
Jp Calderone <exarkun at divmod.com> writes:
> 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.
Well, all setDaemon does is prevent the threading module from joining
that thread during a shutdown - so the thread is left alone in peace
to be reclaimed by the operating system rather than by Python itself.
Do you have instances where this has actually provoked a segfault? If
the thread is executing in Python code, the GIL should prevent it from
actually running during the Python portion of the shutdown, and the OS
will just clean up. If the thread is truly blocked outside of Python
then nothing Python does will be a problem (unless the external entity
is writing directly to Python structures, but without grabbing the GIL
first which is a buggy extension), and the OS will again clean up.
Anyway, I've definitely used daemon threads before where it was
infeasible to guarantee the ability to signal the thread to shut
itself down before I wanted to exit and at least in my experience I've
never run into a problem.
More information about the Twisted-Python