Hi,

2014/1/18 Ben Darnell <[email protected]>:
> +1 to some form of slow-callback detection.
>
> Tornado's version of this idea works a little differently: it uses
> signal.setitimer() and logs a stack trace from the signal handler.  This has
> the advantage that it works even for deadlocks or infinite loops that will
> never return normally, and it also sidesteps the problem of needing a
> printable representation of the callback.  On the other hand, it is less
> portable and signals introduce their own category of bugs (including both
> garbled output in the logs and the fact that some common libraries do not
> properly retry on EINTR), so it is disabled by default and must be turned on
> explicitly.

Since Python 3.3, you can use faulthandler.dump_traceback_later(60.0,
exit=True) to dump the traceback of all Python threads after a timeout
of 60 seconds. Call again this function after each callback to reset
the timeout. See the documentation:
http://docs.python.org/3.3/library/faulthandler.html#faulthandler.dump_traceback_later

The faulthandler module uses a thread, not a signal. It is well
tested, portable and now part of Python. You can find it as a
third-party module on PyPI. The version on PyPI uses signal.alarm()
and so is less portable, may interrupt a system call.

Victor

Reply via email to