Python ThreadPoolExecutor 限制_work_queue 大小

楚江王
• 阅读 3631

使用python的futures.ThreadPoolExecutor是,如果调用submit提交任务
ThreadPoolExecutor的会向执行

self._work_queue.put(w)

其中

self._work_queue = queue.SimpleQueue()

SimpleQueue 是不限制队列大小的,如果提交的任务太多,处理不及时,则导致占用太多内存

可以替换到_work_queue的实现,使用queue.Queue(maxsize=maxsize)

class ThreadPoolExecutorWithQueueSizeLimit(futures.ThreadPoolExecutor):
    def __init__(self, maxsize=50, *args, **kwargs):
        super(ThreadPoolExecutorWithQueueSizeLimit, self).__init__(*args, **kwargs)
        self._work_queue = queue.Queue(maxsize=maxsize)

links:

点赞
收藏
评论区
推荐文章
Easter79 Easter79
3年前
svg自适应写法
svg自适应写法<pre<!DOCTYPEhtml<htmllang"en"<head<metacharset"UTF8"<titleDocument</title</head<body<divstyle"width:30%;height:3.6rem;"<svg
Stella981 Stella981
3年前
InsightFace源码以及pre
一下摘自:https://blog.csdn.net/Fire\_Light\_/article/details/79602705(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2FFire_Light_%2Farticle%2Fdetails%2F7960
Stella981 Stella981
3年前
Python3:sqlalchemy对mysql数据库操作,非sql语句
Python3:sqlalchemy对mysql数据库操作,非sql语句python3authorlizmdatetime2018020110:00:00coding:utf8'''
Wesley13 Wesley13
3年前
01.Android线程池实践基础
目录介绍01.实际开发问题02.线程池的优势03.ThreadPoolExecutor参数04.ThreadPoolExecutor使用05.线程池执行流程06.四种线程池类07.execute和submit区别08.线程池的使用技巧01.实际开发问题
Easter79 Easter79
3年前
TiDB Pre
8月30日,TiDB发布PreGA版。该版本对MySQL兼容性、SQL优化器、系统稳定性、性能做了大量的工作。TiDB:SQL查询优化器调整代价模型优化索引选择,支持不同类型字段比较的索引选择支持基于贪心算法的JoinReorder
Stella981 Stella981
3年前
HTML5新增input标签属性
一.inputtype属性1<formaction""2邮箱<inputtype"email"name""id""<inputtype"submit"value"提交"<br/<br/3手机号码<inputtype"tel"name
Stella981 Stella981
3年前
Pre
PAT甲级1119,我先在CSDN上面发布的这篇文章:https://blog.csdn.net/weixin\_44385565/article/details/89737224(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2Fweixin_443855
Wesley13 Wesley13
3年前
Unity 获取场景中所有目标对象(包括不激活的对象)
usingUnityEngine;usingUnityEditor;usingSystem.Collections.Generic;publicclassExampleScript:MonoBehaviour{//获取场景中所有目标对象(包括不激活的对象)不包括Pre
Stella981 Stella981
3年前
Django之常用配置
<h1在其它文件导入及变量命名注意事项</h1变量命名:必须都大写<preclass'brush:python'fromdjango.confimportsettings</pre<h1静态文件夹配置</h1比如需要引入jquery、bootstrap等文件,需要配置静态文件,步骤如下:步骤一、在<项目名称目录下新建
Stella981 Stella981
3年前
Python code question 1
Question1Level1Question:Writeaprogramwhichwillfindallsuchnumberswhicharedivisibleby7butarenotamultipleof5,between2000and3200(bothincluded).The
ThreadPoolExecutor线程池内部处理浅析 | 京东物流技术团队
我们知道如果程序中并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束时,会因为频繁创建线程而大大降低系统的效率,因此出现了线程池的使用方式,它可以提前创建好线程来执行任务。本文主要通过java的ThreadPoolExecutor来查看线程池