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 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝