从 Pylons 调用的 Process() 创建一个分叉
我正在尝试为主 Pylons 进程中的一些繁重计算创建一个后台进程。代码如下:
p = Process(target = instance_process, \
args = (instance_tuple.instance, parent_pipe, child_pipe,))
p.start()
该进程已创建并启动,但似乎是主进程的一个分支:它正在侦听同一端口,并且整个应用程序挂起。我做错了什么?
提前致谢。
I'm trying to create a background process for some heavy calculations from the main Pylons process. Here's the code:
p = Process(target = instance_process, \
args = (instance_tuple.instance, parent_pipe, child_pipe,))
p.start()
The process is created and started, but is seems to be a fork from the main process: it is listening to the same port and the whole application hangs up. What am I doing wrong?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
进程是一个分叉。如果您查看它的实现,您会发现
Process.start()
调用了一个 fork。但是,它不会调用任何 exec 变体来更改执行上下文。不过,这可能与侦听同一端口无关(除非父进程是多线程的)。程序在什么时候挂起?
我知道,当您尝试关闭 python 程序而不终止通过多处理创建的子进程时,它将挂起,直到子进程终止。
例如,如果您没有关闭进程之间的管道,则可能会导致这种情况。
Process IS a fork. If you look through it's implementation you'll find that
Process.start()
calls a fork. It does NOT, however, call any of theexec
variations to change the execution context.Still, this may have nothing to do with listening on the same port (unless the parent process is multi-threaded). At which point is the program hanging?
I know that when you try shutting down a python program without terminating the child process created through multiprocessing it will hang until the child process terminates.
This might be caused if, for instance, you do not close the pipe between the processes.