【新手提问】
如题
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.