python - threading-信号量示例
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.....")