How can I use threading in order to run 2 processes simultaneously infinitely? I have a chat program, and I want to input while having stuff print out.
I have done a bit of research into thread, and it seems really complicated. What I have so far is
t = Thread(target=refresh)
t.daemon = True
t.start()
I have a refresh() function.
But I'm pretty sure this is wrong, and I have no idea how to run this infinitely alongside my input. Can someone explain how threading works, and how I can run it infinitely alongside another infinite loop?
You have to start your thread like you did it in your code. The important thing is to wait for the thread to complete (even if it infinite loop) because without it, you program will stop immediatly. Just use
t.join()
And you code will run until t thread is over. If you want two thread, just do like this
t1.start()
t2.start()
t1.join()
t2.join()
And your two thread will run simultanously
For your crash problem, with multithreading, you have to look at Mutex for the IOerror
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With