The nice way of handling this if you can afford it (if you are managing your own threads) is to have an exit_request flag that each threads checks on regular interval to see if it is time for him to exit.
For example:
import threading
classStoppableThread(threading.Thread):"""Thread class with a stop() method. The thread itself has to check
regularly for the stopped() condition."""def __init__(self):
super(StoppableThread, self).__init__()
self._stop = threading.Event()def stop(self):
self._stop.set()def stopped(self):return self._stop.isSet()