Car Racing Using multithreading
What is multithreading?
from threading import Thread
import time
winner=""
def print_time(threadname,delay):
count=0
while count < 5:
global exec
global winner
time.sleep(delay)
count+=1
print("%s\t\t%s"%(threadname,time.ctime(time.time())))
threads = []
try:
t1=Thread(target=print_time,args=("Mahindra XUV500",2))
threads.append(t1)
t2=Thread(target=print_time,args=("Toyota Innova",3))
threads.append(t2)
t3=Thread(target=print_time,args=("Tata Hexa",1))
threads.append(t3)
for t in threads:
t.start()#waits waits for thread to complete
for t in threads:
t.join()#waits waits for thread to complete
except Exception as e:
print(e)
else:
pass
finally:
pass