Skip to content

Instantly share code, notes, and snippets.

@warvariuc
Created April 25, 2013 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warvariuc/5459407 to your computer and use it in GitHub Desktop.
Save warvariuc/5459407 to your computer and use it in GitHub Desktop.
Threads SIGINT
#!/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