Python子进程.uWSGI下的Popen缓慢 [英] Python subprocess.Popen slow under uWSGI

查看:260
本文介绍了Python子进程.uWSGI下的Popen缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个在Fedora 14上运行Cherokee的开发服务器,并使用uWSGI与我的WSGI应用程序进行接口.

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

第一个请求需要10到15秒才能完成(后续请求不到一秒钟). 如果不创建Popen对象,则第一个请求仅需要2-3秒即可完成.当我从Python Shell执行相同的Popen请求时,它是瞬时的.

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?

推荐答案

--close-on-exec

否则,您的新进程将继承套接字

Otherwise your new process will inherit the socket

(这是UNIX标准的行为)

(this is a UNIX standard behaviour)

这篇关于Python子进程.uWSGI下的Popen缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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