Skip to content Skip to sidebar Skip to footer

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:

Post a Comment for "Python 2.7: Child Thread Not Catching Keyboardinterrupt"