multiprocessing.freeze_support() [英] multiprocessing.freeze_support()

查看:1188
本文介绍了multiprocessing.freeze_support()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么多处理模块需要调用特定的功能在冻结"以生成Windows可执行文件时可以工作?

Why does the multiprocessing module need to call a specific function to work when being "frozen" to produce a windows executable?

推荐答案

原因是Windows上缺少fork()(这是 完全不正确).因此,在Windows上,通过创建一个 new 进程来模拟,该进程在其中运行在子进程中运行的代码(在Linux上).由于代码将在技术上不相关的流程中运行,因此必须先将其交付到那里,然后才能运行.交付的方式是先对其进行酸洗,然后通过管道将其从原始流程发送到新流程.此外,还通过将此--multiprocessing-fork命令行参数传递给该新进程来通知它必须运行管道传递的代码.如果您查看实现freeze_support()函数的功能是检查正在运行的进程是否应该运行通过管道传递的代码.

The reason is lack of fork() on Windows (which is not entirely true). Because of this, on Windows the fork is simulated by creating a new process in which code, which on Linux is being run in child process, is being run. As the code is to be run in technically unrelated process, it has to be delivered there before it can be run. The way it's being delivered is first it's being pickled and then sent through the pipe from the original process to the new one. In addition this new process is being informed it has to run the code passed by pipe, by passing --multiprocessing-fork command line argument to it. If you take a look at implementation of freeze_support() function its task is to check if the process it's being run in is supposed to run code passed by pipe or not.

这篇关于multiprocessing.freeze_support()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆