python多线程demo

来源:互联网 发布:windows pe系统是什么 编辑:程序博客网 时间:2024/06/04 18:51
#coding=utf-8import threadingfrom time import ctime,sleepdef music(func):    for i in range(8):        print "I was listening to %s. %s" %(func,ctime())        sleep(2)def move(func):    for i in range(4):        print "I was at the %s! %s" %(func,ctime())        sleep(3)threads = []t1 = threading.Thread(target=music,args=('music',))#方法 参数threads.append(t1)t2 = threading.Thread(target=move,args=('movie',))threads.append(t2)if __name__ == '__main__':    for t in threads:        t.setDaemon(True)        t.start()    t.join()    print "all over %s" %ctime()
0 0