Re: [問題] 關於threading restart

看板Python作者 (Minimi)時間15年前 (2010/05/17 00:22), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/2 (看更多)

05/16 21:23,
應該用self.start()吧?
05/16 21:23
我大概懂了,你說的是像這樣吧? import threading class myThread(threading.Thread): def __init__(self): self.i = 1 threading.Thread.__init__(self) def start(self): threading.Thread.__init__(self) threading.Thread.start(self) def run(self): print self.i self.i += 1 t = myThread() t.start() t.join() t.start() t.join() 雖然不是很懂其中的緣由,但是真的會動... 感謝啦 ※ 引述《hl4 (Minimi)》之銘言: : 一個thread產生的時候,會依據參數執行 __init__ : 然後可以以t.start()觸發,執行run() : 請問如果我想要同一個thread再執行一次t.start()或run(),我應該怎麼作 : 直接t.start()似乎會產生錯誤 : 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.237.69 ※ 編輯: hl4 來自: 118.160.237.69 (05/17 00:22)

05/17 01:24, , 1F
麻煩你看一下Lib/threading.py裡的Thread然後不要亂改...
05/17 01:24, 1F
文章代碼(AID): #1By1kxAu (Python)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1By1kxAu (Python)