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()
?
如果使用常规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)导入多处理...
了解set_start_method("spawn")
的功能很重要。