首页 > 编程语言 > 详细

python - threading-semaphore 示例

时间:2017-10-26 16:38:22      阅读:261      评论:0      收藏:0      [点我收藏+]
import threading
import time

def run (n):
semaphore.acquire()
time.sleep(1)
print("run threading :",n)
semaphore.release()
semaphore=threading.BoundedSemaphore(4)
for i in range(20):
t=threading.Thread(target=run,args=(i,))
t.start()
while(threading.activeCount != 1):
pass
else:
print("main threading done.....")

python - threading-semaphore 示例

原文:http://www.cnblogs.com/xiesongyou/p/7737425.html

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