Python多线程案例

 1 from time import ctime,sleep
 2 import threading
 3 def music():
 4     for i in range(2):
 5         print ("I was listening to music. %s" %ctime())
 6         sleep(4)
 7 
 8 def move():
 9     for i in range(2):
10         print ("I was at the movies! %s" %ctime())
11         sleep(5)
12 def eat():
13     for i in range(2):
14         print ("I was at the eats! %s" %ctime())
15         sleep(10)
16 Treads=[]
17 t1 = threading.Thread(target=music)
18 Treads.append(t1)
19 t2 = threading.Thread(target=move)
20 Treads.append(t2)
21 t3 = threading.Thread(target=eat)
22 Treads.append(t3)
23 if __name__ == '__main__':
24     for t in Treads:
25         t.setDaemon(True)
26         t.start()
27     for t in Treads:
28         t.join()
29     print ("all over %s" %ctime())

 

转载于:https://www.cnblogs.com/Erick-L/p/6385543.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值