Created
April 25, 2013 12:41
-
-
Save warvariuc/5459407 to your computer and use it in GitHub Desktop.
Threads SIGINT
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 python | |
import threading | |
def handleSigint(*args): | |
print 'Received SIGINT. Notifying worker threads to stop.', args | |
global shutdown | |
shutdown = True | |
shutdown = False | |
import signal | |
signal.signal(signal.SIGINT, handleSigint) | |
def test(suffix): | |
while not shutdown: | |
pass #print suffix, | |
def main(): | |
global threads | |
threads = [] | |
for i in xrange(5): | |
thread = threading.Thread(target=test, args=(i, )) | |
threads.append(thread) | |
thread.start() | |
signal.pause() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment