myThread问题,过期问题?

时间:2016-07-05 15:04:03

标签: python multithreading

当我运行一个脚本时,它会执行除了线程...我收到此错误:

Traceback (most recent call last):
  File "script.py", line 133, in <module>
    thread = myThread(i, "Thread " + str(i), i);    
  File "script.py", line 100, in __init__
    self.name = name
  File "/usr/lib/python2.7/threading.py", line 971, in name
    assert self.__initialized, "Thread.__init__() not called"
AssertionError: Thread.__init__() not called

这是因为myThread参考已经过时了Python2.7 / threading.py吗?是否应将脚本行更改为其他内容?

1 个答案:

答案 0 :(得分:1)

class myThread (threading.Thread):
    def __init__(self, threadID, name, counter):
    threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.counter = counter
    def run(self):
        print "[+] Starting " + self.name
        connect(self.name, self.counter, eachThread, self.threadID)

这应该可以解决这个问题,只是错误地放了这行“threading.Thread。 init (self)”