In the following program the two threads (myFirstThread, mySecondThread) are executed randomly. The result may vary after each run.
from threading import Thread
from time import sleep, perf_counter
def startThread():
print("Started thread...")
sleep(2)
print("Done")
start = perf_counter()
myFirstThread = Thread(target=startThread)
mySecondThread = Thread(target=startThread)
myFirstThread.start()
mySecondThread.start()
end = perf_counter()
time = end - start
print(myFirstThread)
print(mySecondThread)
print("Time: " + str(round(time, 5)) + " seconds")
Started thread...
<Thread(Thread-7, started 123145644072960)>
<Thread(Thread-8, started 123145677651968)>
Time: 0.00685 seconds
Started thread...
DoneDone