is_TIMI 2019-11-03 23:34 采纳率: 0%
浏览 2464

python多线程最大线程数默认设置为什么与CPU数量有关。

【新手提问】

如题

python多线程最大线程数默认设置为什么与CPU数量有关。按照平时的了解,由于CPython 解释器,python的多线程不是伪多线程吗?实际上并不能使用到多个CPU,那为什么官方的默认设置线程池中最大线程数会与CPU数相关?

concurrent.futures的文档:

Changed in version 3.5: If max_workers is None or not given, 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.

Changed in version 3.8: Default value of max_workers is changed to min(32, os.cpu_count() + 4). This default value preserves at least 5 workers for I/O bound tasks. It utilizes at most 32 CPU cores for CPU bound tasks which release the GIL. And it avoids using very large resources implicitly on many-core machines.

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-11-04 10:24
    关注

    注意文档说 Changed in version 3.5:
    新版的python(3.2开始)GIL已经改进,不再因为GIL的关系而始终“伪多线程”。

    http://blog.chinaunix.net/uid-9162199-id-3182669.html

    评论

报告相同问题?