有沒有人知道如何在不使用全局變量的情況下將代碼中的變量(或變量)從threadOne發送到threadTwo?如果不是,我將如何操作一個全局變量?只需在兩個類之前定義它並在運行函數中使用全局定義?在類線程之間發送消息Python
import threading
print "Press Escape to Quit"
class threadOne(threading.Thread): #I don't understand this or the next line
def run(self):
setup()
def setup():
print 'hello world - this is threadOne'
class threadTwo(threading.Thread):
def run(self):
print 'ran'
threadOne().start()
threadTwo().start()
感謝
我是否在類的外面定義這些? –
你應該在開始使用它們之前創建隊列,所以是的,在線程類之外/之前。 –