Created
November 9, 2013 12:20
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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