#!/usr/bin/env python
# -*- coding: utf-8 -*-
import queue
import threading

class threadpool():
def __init__(self,max_num):
self.q = queue.Queue(max_num)
for i in range(max_num):
self.q.put(threading.Thread)

def get_thread(self):
return self.q.get()
def add_thread(self):
return self.q.put(threading.Thread)

pool = threadpool(5)

def func(i,pool):
import time
time.sleep(1)
print(i)
pool.add_thread()

for i in range(30):
thread = pool.get_thread()
t = thread(target=func,args=(i,pool))
t.start()

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2021-07-31
  • 2022-12-23
  • 2021-11-20
  • 2021-07-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-23
  • 2022-01-05
  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案