简体   繁体   中英

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()

for some reason threadTwo never starts and the output is always threadOne but when I switch the positioning of threadTwo over threadOne then threadOne doesn't run. I suppose it is the way they are getting into queue but, I don't know how to fix it.

The problem is how you pass the functions to the threads. You call them instead of passing the callable. You can fix that by removing the brackets () :

print("thread two")
threadTwo = Thread(target=mainLoop)
print("thread one")
threadOne = Thread(target=pingGetterLoop)

As both functions contain a endless loop, you never get past calling the first one, which then loops forever.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM