python - Python 多处理运行自己而不是导入的脚本
问题描述
尝试使用 Python 进行多处理的新手,但是根据我在本网站和其他地方阅读的内容,我所经历的没有任何意义。这是我的代码:
import multiprocessing as mp
import some_func
cpu_count = mp.cpu_count()
print(cpu_count)
## Some code to build list of function arguments in list 'tasks'
pool = mp.Pool(cpu_count)
if __name__ == '__main__':
for x in tasks:
pool.apply_async(some_func.func, x)
pool.close()
pool.join()
some_func.func 的第一行是:
print('running import',first_variable)
所以每次启动函数时我都应该清楚地看到。
相反,我看到 cpu_count 变量连续打印出来,而 some_func.func 从未被调用。
解决方案
推荐阅读
- css - `&#my-id` 在 CSS 或 SASS 中是什么意思?
- android - FireBase signInWithEmailAndPassword 没有做任何事情
- java - buildnumber-maven-plugin 是如何工作的?
- javascript - Select2 插件由
- tfs - TFS 2018 树查询
- java - 能够查看jsp页面,提交得到404,正确的servlet映射在web.xml中给出。我可以知道是否还缺少其他东西吗?
- module - 加载时的 F# 模块效果
- python - Pandas:运行函数以应用于数据集
- design-patterns - 样本工厂模式输出不显示
- angular - 使用角度 5 合并数组