问题
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