I looked online and found some SO discussing and ActiveState recipes for running some code with a timeout. It looks there are some common approaches:
An other way is to use faulthandler:
import time import faulthandler faulthandler.enable() try: faulthandler.dump_tracebacks_later(3) time.sleep(10) finally: faulthandler.cancel_dump_tracebacks_later()
N.B: The faulthandler module is part of stdlib in python3.3.