pytho线程信号量
作者:互联网
pytho线程信号量
import threading,time def going(num,sleep_time): semaphore.acquire()#启动允许执行 print("gonging is %s"%num) time.sleep(sleep_time) semaphore.release()#释放 if __name__=="__main__": semaphore = threading.BoundedSemaphore(5) #最多允许10个线程同时运行 for i in range(20): t = threading.Thread(target=going,args=(i,1)) t.start()
标签:__,pytho,semaphore,信号量,threading,线程,time,sleep 来源: https://www.cnblogs.com/leo0362/p/10916620.html