[英]Only one thread is starting python
def pingGetterLoop():
while(1):
pingGetter()
def mainLoop():
root.mainloop()
print("thread two")
threadTwo = Thread(target = mainLoop())
print("thread one")
threadOne = Thread(target = pingGetterLoop())
threadOne.start()
threadTwo.start()
由於某種原因,threadTwo永遠不會啟動,輸出總是threadOne,但是當我通過threadOne切換threadTwo的定位時,threadOne就不會運行了。 我想這是他們進入隊列的方式,但我不知道如何修復它。
問題是如何將函數傳遞給線程。 你調用它們而不是傳遞callable。 你可以通過刪除括號()
來解決這個問題:
print("thread two")
threadTwo = Thread(target=mainLoop)
print("thread one")
threadOne = Thread(target=pingGetterLoop)
由於這兩個函數都包含無限循環,因此您永遠不會過去調用第一個函數,然后永遠循環。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.