码迷,mamicode.com
首页 > 编程语言 > 详细

Python 的多线程模块(threading)

时间:2015-09-10 12:32:37      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

1.

 1 #coding=utf-8
 2 import threading
 3 from time import ctime,sleep
 4 
 5 
 6 def music(func):
 7     for i in range(2):
 8         print "I was listening to %s. %s" %(func,ctime())
 9         sleep(1)
10 
11 def move(func):
12     for i in range(2):
13         print "I was at the %s! %s" %(func,ctime())
14         sleep(5)
15 
16 threads = []
17 t1 = threading.Thread(target=music,args=(u爱情买卖,))
18 threads.append(t1)
19 t2 = threading.Thread(target=move,args=(u阿凡达,))
20 threads.append(t2)
21 
22 if __name__ == __main__:
23     for t in threads:
24         t.setDaemon(True)
25         t.start()
26 
27     print "all over %s" %ctime()

 

Python 的多线程模块(threading)

标签:

原文地址:http://www.cnblogs.com/IDomyself/p/4797062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!