def setup_thread_debugger():
"""Setup a thread debbuger for pytest session
This function, based on http://stackoverflow.com/a/133384, is meant to
add debugging facility to pytest that will allow to debug deadlock that
may sometimes occur.
"""
def debug(signal, frame):
"""Interrupt running process and provide a python prompt for
interactive debugging."""
d = {'_frame': frame} # Allow access to frame object.
d.update(frame.f_globals) # Unless shadowed by global
d.update(frame.f_locals)
i = code.InteractiveConsole(d)
message = "Signal received : entering python shell.\nTraceback:\n"
message += ''.join(traceback.format_stack(frame))
i.interact(message)
signal.signal(signal.SIGUSR1, debug) # Register handler
评论列表
文章目录