塔和僵尸进程
我正在尝试编写一个应用程序,允许用户启动长时间运行的计算过程(例如几个小时)。为此,我使用 Python Popen()
函数。只要主 Pylons 进程工作正常,一切都很好,但是当我重新启动 Pylons 进程时,如果上次粘贴启动留下了任何僵尸进程,它不会响应任何请求。
此问题的根源或解决方法可能是什么?
预先感谢,伊万。
I'm trying to write an application that will allow the user to start long-running calculation processes (a few hours, for example). To do so, I use Python Popen()
function. As long as the main Pylons process works fine, everything is good, but when I restart the Pylons process, it doesn't respond to any requests if there are any zombie processes left from the previous paster launch.
What could be the origin or a workaround for this problem?
Thanks in advance, Ivan.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了避免僵尸进程,子进程必须执行双分叉以将其自身与控制进程分离。请参阅 http://en.wikipedia.org/wiki/Zombie_process
所以你需要做的就是让您的子进程再次分叉 - 同时小心地保持相关文件句柄打开,以便您仍然可以进行通信。
To avoid zombie processes, the child must do a double fork to detach itself from the controlling process. See http://en.wikipedia.org/wiki/Zombie_process
So all you need to do is make your child process fork again - while being careful to keep the relevant file handles open so that you can still communicate.
您需要某种消息传递。这可以通过安装信号处理程序来完成。 Python 有用于此目的的
signal
模块,并且Popen
有一个send_signal
方法。也许 http://www.doughellmann.com/PyMOTW/subprocess/#signaling- Between-processes 也可以帮助你。
You need some kind of message passing. This maybe done by installing a signal handler. Python has the
signal
module for this andPopen
has asend_signal
method.Maybe http://www.doughellmann.com/PyMOTW/subprocess/#signaling-between-processes helps you too.