Python 3.3+faulthandlerfunction
faulthandler.cancel_dump_traceback_later()
dump on timeout
Cancels the timer set by dump_traceback_later(): if the code finished in time, no dump happens.
Syntax
faulthandler.cancel_dump_traceback_later()
Put it in finally: without cancelling, the timer fires later somewhere else in the program and raises a false alarm — and with exit=True it kills the process too. The module has a single timer, so the function cancels the last one set and takes no arguments. Calling it with no active timer is harmless.
Examples
import faulthandler, time
with open('hang.txt', 'w') as f:
faulthandler.dump_traceback_later(0.1, file=f)
try:
total = sum(range(1000))
finally:
faulthandler.cancel_dump_traceback_later()
time.sleep(0.2)
print(repr(open('hang.txt').read())) # → ''
See also
Open in the full glossarydocs.python.orgReport an inaccuracy