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

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

    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发