多线程

Posted 糖饼好吃

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多线程相关的知识,希望对你有一定的参考价值。


#coding=utf-8
from time import ctime,sleep
import threading

def music(func):
    for i in range(2):
        print "I was listen to %s. %s" %(func,ctime())
        sleep(3)

def move(func):
    for i in range(2):
        print "I was at the  %s! %s" %(func,ctime())
        sleep(5)

threads = []
t1=threading.Thread(target=music,args=(u\'爱情买卖\',))
threads.append(t1)
t2=threading.Thread(target=move,args=(u\'阿凡达\',))
threads.append(t2)

if __name__ == \'__main__\':
    for t in threads:
        t.setDaemon(True)
        t.start()
    t.join()
    print "all over %s" %ctime()





以上是关于多线程的主要内容,如果未能解决你的问题,请参考以下文章