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
def a():
print("Function a is running at time: " + str(int(time.time())) + " seconds.")
def b():
print("Function b is running at time: " + str(int(time.time())) + " seconds.")
threading.Thread(target=a).start()
OUTPUT
Function a is running at time: 1585338789 seconds.
threading.Thread(target=b).start()
OUTPUT
Function b is running at time: 1585338789 seconds.