多线程

2018-10-19  本文已影响12人  shuff1e

如下是正确用法

import threading

import time

def worker(number):
    print "worker"+str(number),'---start---',time.ctime()
    time.sleep(5)
    print "worker"+str(number),'---end---',time.ctime()


if __name__=='__main__':
    print "main",'---start---',time.ctime()
    threadList=list()
    for i in xrange(5):
        t = threading.Thread(target=worker,args=(i,))
        threadList.append(t)
        t.start()
    for t in threadList:
        t.join()
    print "main",'---end---',time.ctime()
上一篇下一篇

猜你喜欢

热点阅读