Skip to content

Instantly share code, notes, and snippets.

@bak1an
Created November 9, 2013 12:20
Show Gist options
  • Save bak1an/7384887 to your computer and use it in GitHub Desktop.
Save bak1an/7384887 to your computer and use it in GitHub Desktop.
simple threads stack dumper. fancy one can be found here - http://code.activestate.com/recipes/577334-how-to-debug-deadlocked-multi-threaded-programs/
import time
import threading
def stacktraces():
code = []
for threadId, stack in sys._current_frames().items():
code.append("\n# ThreadID: %s" % threadId)
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))
def dumper():
while True:
time.sleep(5)
stacktraces()
threading.Thread(target=dumper).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment