thread termination
--HG-- branch : aspn
This commit is contained in:
25
src/stoppable_thread.py
Normal file
25
src/stoppable_thread.py
Normal 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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user