uWSGI下Python subprocess.Popen慢
我已经设置了一个在 Fedora 14 上运行 Cherokee 的开发服务器,使用 uWSGI 与我的 WSGI 应用程序交互。
当应用程序收到第一个请求时,我会生成一个如下进程:
from subprocess import Popen
Popen(['bash']) # bash is just an example; the problem happens with all programs
第一个请求需要 10-15 秒才能完成(后续请求只需不到一秒)。 如果不创建 Popen 对象,第一个请求只需大约 2-3 秒即可完成。当我从 Python shell 执行相同的 Popen 请求时,它是即时的。
什么可能导致这种行为?我错过了一些明显的事情吗?
I've set up a development server running Cherokee on Fedora 14, using uWSGI to interface with my WSGI application.
When the application is hit with the first request, I spawn a process like so:
from subprocess import Popen
Popen(['bash']) # bash is just an example; the problem happens with all programs
The first request takes 10-15 seconds to complete (subsequent ones take less than a second).
Without the creation of the Popen object, the first request only takes about 2-3 seconds to complete. When I execute the same Popen request from a Python shell, it's instantaneous.
What could be causing this behaviour? Have I missed something obvious?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
--close-on-exec
否则你的新进程将继承套接字
(这是 UNIX 标准行为)
--close-on-exec
Otherwise your new process will inherit the socket
(this is a UNIX standard behaviour)
如果您喜欢在 python 代码中处理此问题,可以选择将 close_fds=True 传递给 Popen() 那么任何套接字都不会被分叉进程继承。
If you prefer to handle this in your python code, you have the option to pass close_fds=True to Popen() then any sockets will not be inherited by the forked process.