Marc Frame
Marc Frame

Reputation: 1001

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.

Upvotes: 1

Views: 1473

Answers (1)

Leon
Leon

Reputation: 3036

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.

Upvotes: 3

Related Questions