Skip to content

Instantly share code, notes, and snippets.

@vfreex
Last active November 12, 2016 14:16
Show Gist options
  • Save vfreex/8904bb57dd751ae078a3b1e3e3f11278 to your computer and use it in GitHub Desktop.
Save vfreex/8904bb57dd751ae078a3b1e3e3f11278 to your computer and use it in GitHub Desktop.
import signal, sys, threading, time
THREADS = []
def handler(signal, frame):
global THREADS
print "Ctrl-C.... Exiting"
for t in THREADS:
t.alive = False
sys.exit(0)
class thread(threading.Thread):
def __init__(self):
self.alive = True
threading.Thread.__init__(self)
def run(self):
n = 0
while self.alive:
n = n + 1
print("round %s" %n)
time.sleep(1)
pass
def main():
global THREADS
t = thread()
t.start()
THREADS.append(t)
signal.pause()
for t in THREADS:
t.join()
if __name__ == '__main__':
signal.signal(signal.SIGINT, handler)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment