2016-07-05 5 views
-1

、それがスレッドを除いて実行...私はこのエラーを取得する:myThread参照がPython2.7/threading.pyに古くなっているので、myThreadの問題、旧式の問題?私は、スクリプトを実行すると

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 

は、このですか?スクリプト行を別のものに変更する必要がありますか?

+0

は 'myThread'が呼ぶん'スーパー(...)を紛失し、この問題を修正する必要があります.__のinit __(...) 'または' Thread .__ init __(...) '?それがなければ、それは必要です。 – Delioth

+0

threading.Threadをサブクラス化するときに[RuntimeError:thread。\ _ \ _ init \ _ \ _()が呼び出されない可能性があります](http://stackoverflow.com/questions/7445742/runtimeerror-thread-init-not- 'threading.Thread .__ init __(self)' – scope

+0

特定の行は次のとおりです。スレッドID、名前、カウンター): self.threadID =スレッドID self.name =名前 self.counter =カウンタ threading.Thread .__のinit __(自己) デフ(自己)を実行します。 印刷 "[+]起動" + self.name connect(self.name、self.counter、eachThread 、self.threadID) ' と ' while(i

答えて

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(自己)"

+0

ニース。働いた。ありがとう! –

関連する問題