Python concurrent.futures.ThreadPoolExecutor max_workers

橙三吉。 提交于 2019-12-11 06:03:40

问题


I am searching for a long time on net. But no use. Please help or try to give me some ideas how to achieve this.

When I use python module concurrent.futures.ThreadPoolExecutor(max_workers=None), I want to know the max_workers how much the number of suitable.

I've read the official document. I still don't know the number of suitable when I coding.

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

How to understand "max_workers" better?

For the first time to ask questions, thank you very much.


回答1:


max_worker, you can take it as threads number.

If you want to make the best of CPUs, you should keep it running (instead of sleeping).

Ideally if you set it to None, there will be ( CPU number * 5) threads at most. On average, echo CPU has 5 thread to schedule. Then if one of them falls into sleep, another thread will be scheduled.



来源:https://stackoverflow.com/questions/53385479/python-concurrent-futures-threadpoolexecutor-max-workers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!