[Twisted-Python] Exit all threads upon KeyboardInterrupt

Glyph Lefkowitz glyph at twistedmatrix.com
Tue Jan 14 12:06:35 MST 2014


On Jan 14, 2014, at 6:27 AM, Dustin J. Mitchell <dustin at v.igoro.us> wrote:

> Second, this has nothing whatsoever to do with whether the I/O is
> blocking or not.  Twisted apps can and, believe me from experience, do
> suffer from stuck TCP connections.  Sure, the wasted resources in this
> case are smaller (just a file descriptor, not a thread), but the user
> experience is the same (part of the application hangs irreversibly).
> In fact, this is about the only thing the manhole is used for at
> Mozilla: running `os.close` on stuck fd's.

The lack of 'abortConnection' was a pretty serious design flaw in Twisted's transport interface initially, but that's been resolved for quite some time now.  It should be possible to handle this at the application level on a per-connection basis quite gracefully now.

I mean, your point is correct; you can certainly have "stuck" event sources in Twisted too, without any threads.  And without any intervention it results in exactly the same bad user experience.  I've certainly seen it myself.

However, intervention is easier than with a stuck thread.  You can't interrupt an arbitrary thread; you don't know and can't tell what it is doing without pretty invasive debugging instrumentation.  And, as you note, even before the advent of abortConnection, an os.close() could easily deal with a stuck async FD on a per-connection basis, without need to bring the entire process down.

Finally, we have abortConnection now, so my main point stands; the point was not "never call os._exit" but rather "if you have to call os._exit, there's a bug".  The same is true here: if you have to manhole into your server to call os.close, there's a bug in your application where it's not timing something out and freeing a resource it otherwise could be freeing.

Unless your contention is that there are no bugs in buildbot? ;-)

-glyph

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140114/bb6fc3ce/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4124 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140114/bb6fc3ce/attachment.bin>


More information about the Twisted-Python mailing list