首页 > 其他 > 详细

20190417

时间:2019-04-17 22:59:37      阅读:134      评论:0      收藏:0      [点我收藏+]
import time
import threading
def music(fun):
    for i in range(2):
        print(music)
        time.sleep(2)
        print(end the music)
def mover(func):
    for i in range(2):
        print(movers)
        time.sleep(8)
        print(end the movers)
# IO form --> sleep() blocking
Threads = []
t1 = threading.Thread(target=music,args=(qil,))
t2 = threading.Thread(target=mover,args=(xiu,))
Threads.append(t1)
Threads.append(t2)

begin = time.time()
for t in Threads:
    t.start()
t.join() # available
#t.join() # unavailable
# t2.start() # t1.join() # t2.join() end = time.time() print(combination,end-begin)

THE OUTPUT:

# t.join() is available
music movers end the music music end the music end the movers movers end the movers combination
16.012058973312378
#t.join() isn‘t available

music
movers
combination 0.0
end the music
music
end the movers
movers
end the music
end the movers

 

20190417

原文:https://www.cnblogs.com/pie-o/p/10726672.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!