多线程

作者: shuff1e | 来源:发表于2018-10-19 15:47 被阅读12次

    如下是正确用法

    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()
    

    相关文章

      网友评论

          本文标题:多线程

          本文链接:https://www.haomeiwen.com/subject/rgrfdftx.html