Python 2.7: Child Thread Not Catching Keyboardinterrupt
import sys import time import threading class exThread(threading.Thread): def __init__(self, threadId): threading.Thread.__init__(self) self.threadId = thread
Solution 1:
As far as I know, KeyboardInterrup
is only raised in the main thread. To be able to stop the other threads, make them check for an event from time to time, and then exit voluntarily.
Another option is to mark the child thread as daemon=True
so that it will auto-terminate when the main thread terminates:
th.daemon = True
Additional reading:
- How daemon threads work Daemon Threads Explanation
- But also, daemon threads can be harmful: http://joeshaw.org/2009/02/24/605/
Post a Comment for "Python 2.7: Child Thread Not Catching Keyboardinterrupt"