thread termination

--HG--
branch : aspn
This commit is contained in:
baloan
2010-11-15 22:28:35 +01:00
parent 6092683f0a
commit 2a20e09944
4 changed files with 126 additions and 0 deletions

25
src/stoppable_thread.py Normal file
View File

@@ -0,0 +1,25 @@
# 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()