Skip to content

Instantly share code, notes, and snippets.

@simark
Created November 17, 2014 06:06
Show Gist options
  • Save simark/ef475431a804cad220f2 to your computer and use it in GitHub Desktop.
Save simark/ef475431a804cad220f2 to your computer and use it in GitHub Desktop.
stacktraces of threads in python
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()))
return "\n".join(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment