PYTHON - 为什么多处理池使用 100% 的 CPU?
PYTHON - why multiprocessing Pool using 100% of CPU?
我需要运行一个并行的程序,我用了pythonmultiprocessing.Pool
但是脚本执行使用了所有 4 个单元中的 100%,这增加了 CPU 温度。
有没有办法限制池使用的百分比?
看看文档就知道了:
- https://docs.python.org/2/library/multiprocessing.html#using-a-pool-of-workers
- https://docs.python.org/2/library/multiprocessing.html#multiprocessing.cpu_count
cpu_count = multiprocessing.cpu_count()
Pool(processes=cpu_count // 2) # Use only half of the CPUs
并检查您的 CPU 风扇。
我需要运行一个并行的程序,我用了pythonmultiprocessing.Pool
但是脚本执行使用了所有 4 个单元中的 100%,这增加了 CPU 温度。
有没有办法限制池使用的百分比?
看看文档就知道了:
- https://docs.python.org/2/library/multiprocessing.html#using-a-pool-of-workers
- https://docs.python.org/2/library/multiprocessing.html#multiprocessing.cpu_count
cpu_count = multiprocessing.cpu_count()
Pool(processes=cpu_count // 2) # Use only half of the CPUs
并检查您的 CPU 风扇。