I am using this logic for standard thread canceling:
1. MainThread
- I run input from keyboard in main process/thread
- I can setup event via threading.Event().set()
- See code sample for
class MainThread(threading.Thread)
def __init__(self, *args, **kwargs):
super(StoppableThread, self).__init__(*args, **kwargs)
self._stop_event = threading.Event()
def stop(self):
self._stop_event.set()
def stopped(self):
return self._stop_event.is_set()
2. BackgroudThreads
- Background threads are checking (periodically) this signal state and can close their execution.
BTW: nice clarification see article