我試圖用表現爲an answer to another question的StoppableThread
類:超類__init__不承認其kwargs
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'
可能是應該如何使用它的疏忽。