[Twisted-Python] Uninteruptable infinite loop: Woven rendering

Andrew Bennetts andrew-twisted at puzzling.org
Sun Aug 10 20:20:49 MDT 2003


On Mon, Aug 11, 2003 at 12:06:32PM +1000, Andrew Bennetts wrote:
> 
> Also, bare "except:" clauses can suppress KeyboardInterrupt errors, and a
> quick grep shows a disturbingly large number of these in Twisted (perhaps
> the Coding Standard needs updating?).  That still wouldn't explain why
> SIGTERM doesn't work, though :/

Except of course, Twisted (by default) installs signal handlers to intercept
SIGTERM and SIGINT.  And these just register a call back in the reactor to
shut it down at the next iteration -- but if there's an infinite loop, the
reactor never regains control, so you're stuck.

So, perhaps these signal handlers should:
    a) log that the event happened *immediately*, if it's possible to safely
       use the log file in a signal handler.  That way at least looking at
       the log file you know you're not being completely ignored, and e.g. a
       message like "Caught SIGTERM -- reactor will shutdown on the next
       iteration." would make it clear that if your program isn't shutting
       down, your code isn't returning to the reactor.
    b) keep a counter, so that if 5 SIGINT or SIGTERMs are caught without
       the reactor shutting down, somehow force a shutdown, perhaps
       uncleanly.  Hopefully this can be done without calling os._exit() ;)
       Bonus points for logging a traceback of where-ever the main thread
       was at the time, to help track down infinite loops...

-Andrew.





More information about the Twisted-Python mailing list