Python Pebble ProcessPool如何设置max_任务

2024-04-20 01:36:37 发布

您现在位置:Python中文网/ 问答频道 /正文

Pebble的过程池为max_workers和max_tasks获取参数。在

https://pythonhosted.org/Pebble/#pools

max_任务的描述有点不清楚:

“如果max_tasks是一个大于零的数字,则在执行等量的任务后,每个工作线程都将重新启动。”

我的问题是:

  • 如果不大于零呢?那它会怎么样呢?

  • 重启工人意味着什么?假设最大任务数是5。将重复5次,然后执行一个新的过程?这样做有什么好处?

  • 我知道其他库允许您根据每个任务是否需要相似的时间来定制池映射。这和这里有关吗?

  • 一般来说,设置最大任务有哪些准则?

我正在运行一个函数,这个函数需要在长度为+=160000的列表的每个元素上运行。它是完全可并行的,我的服务器有8个核心。每个函数调用将在相同的时间内完成,最多比平均时间长3倍。在

谢谢。在


Tags: 函数httpsorg参数过程时间数字线程
1条回答
网友
1楼 · 发布于 2024-04-20 01:36:37

max_task参数类似于multiprocessing.Pool中的maxtaskperchild。python2related documentation解释了此类参数的用途。在

Worker processes within a Pool typically live for the complete duration of the Pool’s work queue. A frequent pattern found in other systems (such as Apache, mod_wsgi, etc) to free resources held by workers is to allow a worker within a pool to complete only a set amount of work before being exiting, being cleaned up and a new process spawned to replace the old one. The maxtasksperchild argument to the Pool exposes this ability to the end user.

换句话说,如果您想限制进程可以维持的资源增长量,可以使用max_task。例如,它在处理泄漏内存或文件描述符的库时非常有用。另一个用例是限制进程中发生的内存碎片所浪费的内存。在

相关问题 更多 >