Cleanly exiting multi thread application on SIGINT

jrpfinch jrpfinch at gmail.com
Fri Mar 23 08:40:22 EDT 2007


Is the following the most elegant way to exit a multi-threaded
application on a Ctrl-C?  I am a complete beginner and would have
thought there was some way of doing it without having to use while 1:
pass, but have yet to find a way.

N.B. exit() is a method for cleanly exiting the thread using a queue.

Many thanks

Jon

def main:
    wt = workerThread()
    wt.setDaemon(True)
    wt.start()
    ct = counterThread()
    ct.setDaemon(True)
    ct.start()
    try:
        while 1:
            pass
    except KeyboardInterrupt:
        wt.exit()
        ct.exit()




More information about the Python-list mailing list