我正在使用Python的concurrent.futures模块(模块版本2.1.3,Python版本2.7.3)。我有nginx运行4个工作进程,4个uWSGI运行(在Ubuntu精确)作为一个upstart守护进程,具有以下uwsgi配置(注意enable-threads为true,因此GIL是可访问的,懒惰是真的):
virtualenv=[ path to venv ]
chdir=[ path to python project ]
enable-threads=true
lazy=true
buffer-size=32768
post-buffering=true
processes=4
master=true
module=[ my app ].wsgi
callable=wsgi_app
logto=/var/log/uwsgi.log
pidfile=[ replaced ]
plugins=python27
socket=[ replaced, but works fine ]
整个应用程序工作正常,但似乎期货池无法使用一些缺少的上下文:当我调用somefunc()而没有future()时,一切都很好,但是当我用future调用somefunc()时, HTTP请求(我正在使用Flask)在失败之前会挂起很长时间。
日志文件的唯一条目与HTTP请求和一般的wsgi启动内容相关,如:
WSGI application 0 (mountpoint='') ready on interpreter 0x11820a0 pid: 26980 (default app)
如何了解期货执行情况,或找出期货池可能无法获得的背景?
这有意义吗?
提前致谢。
答案 0 :(得分:2)
如果您使用的是ProcessPoolExecutor而不是线程,请务必在您的uWSGI选项中添加close-on-exec,否则在fork()之后将继承与客户端/ web服务器的连接套接字