Last active
November 12, 2016 14:16
-
-
Save vfreex/8904bb57dd751ae078a3b1e3e3f11278 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
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