Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

run code at the same time python

from threading import Thread
import time

def parallelFunc():
    for i in range(100):
      print("1")
      time.sleep(0.2)
      
def parallelFunc2():
    for i in range(100):
      print("2")
      time.sleep(0.2)
      
th = Thread(target=parallelFunc)
th2 = Thread(target=parallelFunc2)

th.start()
th2.start()

#Run code in parallel with other 2 functions

th.join()
th2.join()

#2 functions will loop at the same time
 
PREVIOUS NEXT
Tagged: #run #code #time #python
ADD COMMENT
Topic
Name
6+5 =