pythonの信号量

#!/usr/bin/env python
import threading,time def run(n):
# 申请锁
semaphore.acquire()
time.sleep(1)
print("run thre thread:%s\n"%n)
# 释放锁
semaphore.release() if __name__ == "__main__":
# 申请线程池,每次最多开辟五个线程
semaphore = threading.BoundedSemaphore(5) for i in range(22):
# 开启一个线程
t = threading.Thread(target=run,args=(i,))
t.start()
while threading.active_count() !=1:
pass else :
print("all threads done")
上一篇:【leetcode】Search for a Range(middle)


下一篇:centos 6.5 编译安装了 Nginx1.6.0+MySQL5.6.19+PHP5.5.14