控制并发的线程数
#-*-coding:utf-8-*-
#__author:martin
#date:2017/10/22
import threading
import time
class Mythread(threading.Thread):
def run(self):
if semaphore.acquire():
print(self.name)
time.sleep(5)
semaphore.release()
if __name__ == '__main__':
semaphore = threading.BoundedSemaphore(5)
threads = []
for i in range(100):
threads.append(Mythread())
for t in threads:
t.start()