Files
aspn/src/stoppable_thread.py
baloan 2a20e09944 thread termination
--HG--
branch : aspn
2010-11-15 22:28:35 +01:00

26 lines
567 B
Python

# http://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python
''' StoppableThread '''
# system imports
from threading import Event, Thread
# definitions
class StoppableThread(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 = Event()
def stop(self):
self._stop.set()
def stopped(self):
return self._stop.isSet()