I have looked through all the previous answers, and they are all too complicated for a beginner like me. I want to run too while loops at the same time. For example, I want to run these two at the same time:
def firstFunction():
do things
def secondFunction():
do some other things
As I said, the other answers are too complex for me to understand.
Assuming your while loops are within the functions you listed, this is the easiest way I can think of.
from threading import Thread
t1 = Thread(target = firstFunction)
t2 = Thread(target = secondFunction)
t1.start()
t2.start()
As pointed out by tdelaney, doing it this way will just kick off each thread and immediately move on. If you need to wait for those threads to complete before running the rest of your program you can use the .join() method.
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