python并行计算 [joblib] Attempting to do parallel computing without protecting。。。

来源:互联网 发布:改手机号码软件 编辑:程序博客网 时间:2024/06/06 04:17

Under Windows, it is important to protect the main loop of code to avoid recursive spawning of subprocesses when using joblib.Parallel. In other words, you should be writing code like this:

import ....def function1(...):    ...def function2(...):    ...... if __name__ == '__main__':    # do stuff with imports and functions defined about    ...


这是必要的,因为Windows没有fork()。由于这个限制,Windows需要在它生成的所有子进程中重新导入您的主模块,以便在子进程中重新创建父进程。这意味着,如果您有在模块级生成新进程的代码,那么它将在所有子进程中递归地执行。if名称==“main”用于防止模块范围内的代码在子进程中被重新执行。这在Linux上是不必要的,因为它有fork(),它允许它派生一个维护相同状态的子进程,而不需要重新导入主模块。

https://stackoverflow.com/questions/29545605/why-is-it-important-to-protect-the-main-loop-when-using-joblib-parallel


阅读全文
0 0
原创粉丝点击