Nov-27-2019, 01:32 PM
(Nov-27-2019, 08:43 AM)tonycstech Wrote: I need to understand how printing 1 and 2 can be done at same time and not one after another.You most use
start()
to spawn separate thread.run()
does not spawn a separate thread,it runs the thread function in the context of the current thread.from threading import Thread import time def Loop1(): while 1: time.sleep(2) print(1) def Loop2(): while 1: time.sleep(6) print(2) process1 = Thread(target=Loop1) process2 = Thread(target=Loop2) process1.start() process2.start()