PyThread.py
import os
from threading import Thread,Lock
from time import *
lock = Lock()
data = 0
startTime = time()
def threadFunc(arg):
global data
global startTime
for i in range(1000):
lock.acquire()
if(data==0):
startTime = time_ns()
if(data==4000):
endTime = time_ns()
passtime = (endTime - startTime)/(1000*1000)
print("Thread Stop data = {},passTime={}ms".format(data,passtime))
lock.release()
return
data +=1
t=time()
print("data = {}, time = {},thread = {}" .format(data,t,arg) )
lock.release()
main.py
for i in range(10):
t = Thread(target=threadFunc,args=(i,))
t.start()
t.join()