python的多线程

#python多线程

try:
    from threading import Thread
    import threading, time, random
except BaseException,e:
    print("import Error %s" % (e.message,))
    

def runThread(*args, **kwargs):
    #ident线程ID
    print("TID=%s TName=%s args=%s kwargs=%s" % \
          (\
              threading.currentThread().ident\
              ,threading.currentThread().getName()\
          ,str(args),str(kwargs)\
          ))
    
    start=time.time()
    time.sleep(2)
    end=time.time()
    print("Thread elasped:%0.2f" % (end-start,))
    

if __name__=="__main__":
    for i in range(5):
        t=Thread(target=runThread, name="t%s" % (i,),args=("test1","test2"), kwargs={'x':10,'y':20})
        t.start()
        t.join(5)

你可能感兴趣的:(python多线程)