可停止的线程错误

时间:2015-12-20 15:39:06

标签: python multithreading python-2.7

我正在创建一个可停止的线程类:

import threading

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()

然而,当我像这样创建对象时:

我收到此错误:

Traceback (most recent call last):
  File "./myFile.py", line 81, in <module>
    aObject = StoppableThread(target, args=("foo", "bar",)))
TypeError: __init__() got an unexpected keyword argument 'args'

提前谢谢。

0 个答案:

没有答案