How to make while(True): two loops run at same time in python How to make while(True): two loops run at same time in python tkinter tkinter

How to make while(True): two loops run at same time in python


How about something like the following. Spawn two processes. Each one runs in parallel and the target functions can be replaced with your own.

from multiprocessing import Processfrom time import sleepdef func1():    while True:        print("func1 up and running")        sleep(1)def func2():    while True:        print("func2 up and running")        sleep(1)if __name__ == '__main__':    proc1 = Process(target=func1)    proc1.start()    proc2 = Process(target=func2)    proc2.start()

The output is:

func1 up and runningfunc2 up and runningfunc1 up and runningfunc2 up and runningfunc1 up and runningfunc2 up and runningfunc1 up and runningfunc2 up and running...