Skip to content

Instantly share code, notes, and snippets.

@cwen0
Created March 28, 2018 06:47
Show Gist options
  • Save cwen0/ec90a202accfdc93966069e09a788ca6 to your computer and use it in GitHub Desktop.
Save cwen0/ec90a202accfdc93966069e09a788ca6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2.7
from threading import Event
exit = Event()
def main():
while not exit.is_set():
do_my_thing()
exit.wait(60)
print("All done!")
# perform any cleanup here
def quit(signo, _frame):
print("Interrupted by %d, shutting down" % signo)
exit.set()
if __name__ == '__main__':
import signal
for sig in ('TERM', 'HUP', 'INT'):
signal.signal(getattr(signal, 'SIG'+sig), quit);
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment