Skip to content

Instantly share code, notes, and snippets.

@FooBarWidget
Created March 11, 2014 21:39
Show Gist options
  • Save FooBarWidget/9495646 to your computer and use it in GitHub Desktop.
Save FooBarWidget/9495646 to your computer and use it in GitHub Desktop.
import threading, traceback, signal, sys
def install_signal_handlers():
def debug(sig, frame):
id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
code = []
for thread_id, stack in sys._current_frames().items():
code.append("\n# Thread: %s(%d)" % (id2name.get(thread_id,""), thread_id))
for filename, lineno, name, line in traceback.extract_stack(stack):
code.append(' File: "%s", line %d, in %s' % (filename, lineno, name))
if line:
code.append(" %s" % (line.strip()))
print("\n".join(code))
signal.signal(signal.SIGQUIT, debug)
install_signal_handlers()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment