Created
May 11, 2024 11:57
-
-
Save luqmanrom/af2528e7aa933a2edebbd0c8a9e57da5 to your computer and use it in GitHub Desktop.
Revisions
-
luqmanrom created this gist
May 11, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ import signal import time import os def handle_sigterm(signum, frame): print("Received SIGTERM. Cleaning up...") print("Cleanup done. Exiting gracefully.") exit(0) def handle_sigint(signum, frame): print("Received SIGINT. Cleaning up...") print("Cleanup done. Exiting gracefully.") exit(0) signal.signal(signal.SIGTERM, handle_sigterm) signal.signal(signal.SIGINT, handle_sigint) print(f"Running process with PID: {os.getpid()}") print( f"SIGKILL: kill -9 {os.getpid()}") print( f"SIGTERM: kill -15 {os.getpid()}") try: while True: time.sleep(1) except KeyboardInterrupt: print("Process interrupted by user.")