解决一例uWSGI假死问题

这个问题很有意思。

症状是,如果使用Python启动Flask,没有任何问题;但是使用uWSGI带着gevent启动app,到一定时间后,这个uWSGI就收不到任何请求了。

这是使用的命令:

uwsgi3 --gevent 8 --gevent-monkey-patch --http :1234 -s /tmp/uwsgi.sock --pythonpath=~/api/ -w new_api:app

uwsgi3 --gevent 8 --gevent-monkey-patch --http :1234 -s /tmp/uwsgi.sock --pythonpath=~/api/ -w new_api:app

有意思的地方在于,刚开始在排查的时候,由于uWSGI没有任何错误提示,很容易误以为是Python3和Python2兼容的问题,或者是gevent的问题。

 

但其实是由于启动时参数不对。应该是--http-socket。

uwsgi3 --gevent 8 --gevent-monkey-patch --http-socket :1234 -s /tmp/uwsgi.sock --pythonpath=~/api/ -w new_api:app

这样就对了。

 

http://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html

在官方文档里也写了这个问题。

Do not use --http when you have a frontend webserver or you are doing some form of benchmark, use --http-socket. Continue reading the quickstart to understand why.

posted @ 2017-01-20 19:22  FRank5433  阅读(2330)  评论(1编辑  收藏  举报