Created
May 22, 2024 14:36
-
-
Save vrbadev/9a68ad5e713420f236f1dc3109c03871 to your computer and use it in GitHub Desktop.
Python termination signal handler using a lambda and a global variable
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 | |
if __name__ == "__main__": | |
terminated = False | |
signal.signal(signal.SIGINT, lambda sig, frame: globals().update(terminated=True)) | |
while not terminated: | |
# do something ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment