gpt4 book ai didi

Python并发.futures.ThreadPoolExecutor max_workers

转载 作者:行者123 更新时间:2023-12-01 01:25:34 34 4
gpt4 key购买 nike

我在网上找了好久。但没有用。请帮助或尝试给我一些如何实现这一目标的想法。

当我使用python模块concurrent.futures.ThreadPoolExecutor(max_workers=None)时,我想知道max_workers多少个合适。

我已经阅读了官方文档。我编码时仍然不知道合适的数量。

Changed in version 3.5: If max_worker is None or not give, it will default to the number of processors on the machine, multiplied by 5, assuming that ThreadPoolExecutor is often used to overlap I/O instead of CPU work and the number of workers should be higher than the number of workers for ProcessPoolExecutor.

如何更好地理解“max_workers”?

第一次提问,非常感谢。

最佳答案

max_worker,可以将其视为线程数。

如果你想充分利用 CPU,你应该让它保持运行(而不是休眠)。

理想情况下,如果将其设置为 None,则最多会有 (CPU 数量 * 5) 个线程。平均每个CPU有5个线程需要调度。然后,如果其中一个线程进入休眠状态,则会调度另一个线程。

关于Python并发.futures.ThreadPoolExecutor max_workers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53385479/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com