Created
October 23, 2024 12:06
-
-
Save ivarref/bba6f7f38c3eda732f0d54146e4b79e3 to your computer and use it in GitHub Desktop.
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 faulthandler | |
import multiprocessing | |
import os | |
import signal | |
def run_buggy(): | |
shutdown_event = multiprocessing.Event() | |
def sigterm_handler(_signo, _stack_frame): | |
try: | |
print(f'sigterm_handler running') | |
shutdown_event.set() | |
finally: | |
print(f'sigterm_handler done') | |
signal.signal(signal.SIGTERM, sigterm_handler) | |
signal.signal(signal.SIGINT, sigterm_handler) | |
faulthandler.register(signal.SIGUSR1) | |
print(f'Running process with PID {os.getpid()}') | |
print(f'Dump the stack by executing:') | |
print(f'kill -SIGUSR1 {os.getpid()}') | |
print(f'Try to kill this process with CTRL-C or kill {os.getpid()} ...') | |
while not shutdown_event.is_set(): | |
pass | |
if __name__ == '__main__': | |
run_buggy() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment