Last active
March 10, 2022 22:31
-
-
Save Kylep342/4edb39948cacb99f4a37c6c81f1f830e to your computer and use it in GitHub Desktop.
Dump the stack traces of all executing Python threads when the Python Process receives the `usr1` signal.
This file contains hidden or 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 signal | |
import sys | |
import traceback | |
def sigterm_handler(signal, frame): | |
# save the state here or do whatever you want | |
for thread_id, frame in sys._current_frames().items(): | |
logger.info(f"Stack for thread {thread_id}") | |
traceback.print_stack(frame, file=sys.stdout) | |
logger.info("") | |
signal.signal(signal.SIGUSR1, sigterm_handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: