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

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?