
Python多线程控制线程数量
import time import threading sem = threading.Semaphore(2) #限制线程最大数量 def function(c,d): with sem: #锁定线程的最大数量 print(str(c) + ' '+ str(d)) time.sleep(3) print('-----------------') for c in range(1,255): ts=threading.Thread(target=function,args=(c,c)) ts.start()
👁️ 阅读量:0
© 版权声明:本文《Python多线程控制线程数量》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686659540a319335.html。