我试图使用作为另一个问题的答案介绍的StoppableThread
类:
import threading
# Technique for creating a thread that can be stopped safely
# Posted by Bluebird75 on StackOverflow
class StoppableThread(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()
然而,如果我运行下面这样的东西:
st = StoppableThread(target=func)
我得到了以下报错信息:
``` TypeError: __init__() got an unexpected keyword argument 'target' ```
很可能是关于如何使用它的疏忽导致的。