Reputation: 21
I am currently trying to thread two loops in python. One is currently a tkinter loop that displays the the gui I have set up, and the other is a p2p chat function. using 'import threading', defining threads and starting them individually doesn't seem to work. Any suggestions for what method I can use to get these two loops running concurrently?
The code I'm using to start the threads:
thread1 = threading.Thread(target=x.mainloop())
thread1.start()
thread2 = threading.Thread(target=root.mainloop())
thread2.start()
Upvotes: 0
Views: 50
Reputation: 155323
You need to pass the functions without calling them. As is, you're trying to call them, and pass the return value as the target
for the thread; since they never return, you never launch the second thread. Try:
thread1 = threading.Thread(target=x.mainloop) # Removed call parens on target
thread1.start()
thread2 = threading.Thread(target=root.mainloop) # Removed call parens on target
thread2.start()
Upvotes: 1