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