Skip to content

Instantly share code, notes, and snippets.

@beaugunderson
Created May 9, 2020 17:20
Show Gist options
  • Save beaugunderson/6644da1dfd9bad3cdc0f299e3174846d to your computer and use it in GitHub Desktop.
Save beaugunderson/6644da1dfd9bad3cdc0f299e3174846d to your computer and use it in GitHub Desktop.
#!/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