python - Python中的多级多处理
问题描述
我意识到我的问题非常广泛,但我也在寻找广泛的答案:)
我有 2 个功能:outer
和inner
.
import traceback
import multiprocessing
def inner():
return "blah"
def outer():
success: bool = True
process_pool: multiprocessing.Pool = multiprocessing.Pool(XXX)
try:
process_pool.map(inner)
process_pool.close()
except Exception as ex:
print(ex)
print(traceback.print_exc())
success = False
process_pool.terminate()
except KeyboardInterrupt as ex:
print(ex)
success = False
process_pool.terminate()
finally:
process_pool.join()
return success
我现在想创建一个space
执行outer
方式相同的函数outer
executes inner
。
def space():
success: bool = True
process_pool: multiprocessing.Pool = multiprocessing.Pool(YYY)
try:
process_pool.map(outer)
process_pool.close()
except Exception as ex:
print(ex)
print(traceback.print_exc())
success = False
process_pool.terminate()
except KeyboardInterrupt as ex:
print(ex)
success = False
process_pool.terminate()
finally:
process_pool.join()
return success
假设我有 100 个 CPU 可供使用。如何设置该space
功能?在 XXX 和 YYY 之间拆分(每个多处理函数中的 CPU 数量)?这样做是否明智?
解决方案
推荐阅读
- html - 显示所有正确 CSS 设置的图像边框线
- react-native - 改变风格反应原生材料下拉
- r - 如何使用 R 中的枢轴连接不连续的列
- python - 按日期过滤 ListView 中的对象 - Django
- ios - 数组元素拼接字符
- google-home - 更改 Wifi 密码后无法访问 Google Home Mini
- javascript - 我不明白为什么当两个代码明显相同时会发生这种情况
- google-apps-script - 使用 Google App Script 而非 Google Drive API 存储应用程序特定数据
- hl7-fhir - 验证资源是否符合搜索条件?
- c# - 从 C# 中的方法返回泛型列表