uWSGI:Python的concurrent.futures在所有uWSGI进程中挂起,唯独一个例外

1 投票
1 回答
1864 浏览
提问于 2025-04-17 16:26

我在用Python的concurrent.futures模块(版本2.1.3,Python版本2.7.3)。我有一个nginx在运行,配置了4个工作进程,还有4个uWSGI在运行(在Ubuntu precise上),作为一个upstart守护进程,uwsgi的配置如下(注意enable-threads设置为真,这样GIL是可用的,lazy也设置为真):

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 ]

整个应用运行得很好,但似乎有一些缺失的上下文没有传递给futures池:当我直接调用somefunc()时,一切正常,但当我用future调用somefunc()时,HTTP请求(我在用Flask)会挂起一段时间,然后才失败。

日志文件中只有与HTTP请求相关的条目,还有一些一般的wsgi启动信息,比如:

WSGI application 0 (mountpoint='') ready on interpreter 0x11820a0 pid: 26980 (default app)

我该如何查看futures的执行情况,或者弄清楚哪些上下文可能没有传递给futures池呢?

这样说清楚了吗?

提前谢谢你。

1 个回答

2

如果你使用的是 ProcessPoolExecutor 而不是线程,记得在你的 uWSGI 选项中添加 close-on-exec。否则,在进行 fork() 操作后,和客户端或网页服务器的连接会被继承,这可能会导致一些问题。

撰写回答