1 import threading
 2 from time import sleep,ctime 
 3 
 4 def print1():
 5     for i in range(10):
 6         print(i,end='')
 7         print('  0123456789  %s' % ctime())
 8         sleep(4)
 9 
10 def print2():
11     for i in range(10):
12         print(i,end='')
13         print('  哈哈        %s' % ctime())
14         sleep(3)
15 
16 
17 
18 t1 = threading.Thread(target=print1)#t1 = threading.Thread(target=music,args=('参数',))
19 t2 = threading.Thread(target=print2)
20 threads = [t1,t2]
21         
22 for t in threads:
23     t.setDaemon(True)#父进程结束,就杀死子进程
24     t.start()
25                 
26 for t in threads:#等待进程结束
27     t.join()
28 print('OK!')

 

posted on 2019-04-30 16:17  苏州城外啲微笑  阅读(161)  评论(0编辑  收藏  举报