Last active
September 17, 2015 12:38
-
-
Save jaysonsantos/4838023f1d07c755cb1f to your computer and use it in GitHub Desktop.
Mimic java and dump all threads stacktrace when CRTL + \ is pressed
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 functools | |
import signal | |
import sys | |
import time | |
import traceback | |
import threading | |
lock = threading.Lock() | |
def _dump_data(): | |
with lock: | |
sys_err = open('/dev/stderr', 'w') | |
log = functools.partial(print, file=sys_err, flush=True) | |
threads = {thread.ident: thread for thread in threading.enumerate()} | |
for ident, frame in sys._current_frames().items(): | |
log('=' * 80) | |
log('Thead', threads[ident].name, ident) | |
log(''.join(traceback.format_stack(frame))) | |
log('=' * 80, '\n\n\n') | |
def dump_data(*args, **kwargs): | |
threading.Thread(target=_dump_data).start() | |
signal.signal(signal.SIGQUIT, dump_data) | |
while True: | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment