import time lst=[] lock=threading.BoundedSemaphore(2) def fun(arg): lock.acquire() print(arg) # lst.append(arg) time.sleep(1) # m=lst[-1] lock.release() for i in range(10): t=threading.Thread(target=fun,args=(i,)) t.start()
threading.BoundedSemaphore
最新推荐文章于 2024-10-18 12:27:51 发布