Ubuntu,cx_Freeze和multiprocessing.Manager()在“生成”类型的情况下发生冲突

问题描述 投票:1回答:1

Env:

Ubuntu-18.04Python-3.6.6cx_Freeze-6.1

代码:

简单main_script.py文件(存储库中的示例-https://github.com/Yuriy-Leonov/cython_multiprocessing_issue

import multiprocessing

if __name__ == '__main__':
    print("step-1")
    multiprocessing.set_start_method("spawn")
    print("step-2")
    multiprocessing.freeze_support()
    print("step-3")
    manager = multiprocessing.Manager()
    print("step-4")
    s_dict = manager.dict()
    print("finish")

setup.py(对于cx_Freeze):

import cx_Freeze

executables = [cx_Freeze.Executable("main_script.py")]

cx_Freeze.setup(
    name="Example",
    options={
        "build_exe": {
            "replace_paths": [("*", "")]
        },
    },
    executables=executables
)

问题:

通过命令python setup.py build构建可执行文件后,我运行了该文件,并且控制台日志包含以下内容:

step-1
step-2
step-3
step-1
step-2
step-3
step-1
step-2
step-3
...

并且会产生无限的过程。我知道multiprocessing.Manager()应该产生“服务器”进程。但是无法了解当前行为以及如何强制其创建“共享字典”的线索]

重要:

[multiprocessing.set_start_method("spawn")由于主程序的行为而不能更改和必需。

问题:

如何在当前配置中创建manager.dict()

PS:

如果使用常规python <filename>(显而易见)运行,则没有问题>

Env:Ubuntu-18.04 Python-3.6.6 cx_Freeze-6.1代码:简单的main_script.py文件(存储库中的示例-https://github.com/Yuriy-Leonov/cython_multiprocessing_issue)导入多处理...

python linux ubuntu multiprocessing cx-freeze
1个回答
0
投票

了解set_start_method("spawn")的功能很重要。

© www.soinside.com 2019 - 2024. All rights reserved.