Created
May 9, 2020 17:20
-
-
Save beaugunderson/6644da1dfd9bad3cdc0f299e3174846d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 -u | |
import signal | |
class Runner: | |
def __init__(self): | |
self.stop = False | |
self.previous_handler = signal.signal(signal.SIGINT, self.cb_signal_handler) | |
print('Ctrl+c to stop') | |
def __delete__(self, instance): | |
signal.signal(signal.SIGINT, self.previous_handler) | |
def cb_signal_handler(self, *args, **kwargs): | |
self.stop = True | |
print('Stopping...') | |
def run(self): | |
i = 0 | |
while True: | |
if self.stop: | |
print('Execution stopped') | |
break | |
# print a . every so often to show progress | |
if i % 100000 == 0: | |
print('.', end='') | |
i += 1 | |
if __name__ == '__main__': | |
runner = Runner() | |
runner.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment