我在使用Apache(mod_wsgi)部署我的Flask应用程序时遇到问题
和共享托管(Webfaction)上的gevent.
该应用程序在Flask提供的开发服务器中运行良好,但是当我
尝试部署它我在日志文件中收到以下错误:
[Tue Mar 13 15:48:24 2012] [error] Traceback (most recent call last):
[Tue Mar 13 15:48:24 2012] [error] File "evdns.pxi", line 78, in gevent.core.__evdns_callback (gevent/core.c:6300)
[Tue Mar 13 15:48:24 2012] [error] File "/home/username/.virtualenvs/staging/lib/python2.7/site-packages/gevent/hub.py", line 297, in switch_args
[Tue Mar 13 15:48:24 2012] [error] File "/home/username/.virtualenvs/staging/lib/python2.7/site-packages/gevent/hub.py", line 290, in switch
[Tue Mar 13 15:48:24 2012] [error] File "/home/username/.virtualenvs/staging/lib/python2.7/site-packages/gevent/hub.py", line 135, in get_hub
[Tue Mar 13 15:48:24 2012] [error] NotImplementedError: gevent is only usable from a single thread
我需要gevent,因为我正在使用python-requests’ async module
制作并发HTTP请求.
我尝试了谷歌,但我发现的唯一建议是打电话
from gevent import monkey
monkey.patch_all()
我在代码中已经做过的事情.
WSGIDaemonProcess的值是:
WSGIDaemonProcess myapp processes=5 python-path=/home/myusername/webapps/myapp/lib/python2.7 threads=1
这是我的httpd.conf:http://pastebin.com/eWygicJH
有人有任何建议来解决这个问题吗?
解决方法:
好像我自己找到了解决方案.以下指令解决了我的问题:
WSGIApplicationGroup %{GLOBAL}
这个想法来自另一个answer,建议将WSGIApplicationGroup设置为GLOBAL以解决WSGI进程不断崩溃的问题. From WSGI documentation:
To force a specific WSGI application to be run within the very first
Python sub interpreter created when Python is initialised, the
WSGIApplicationGroup directive should be used and the group set to
‘%{GLOBAL}’.
无法完全理解为什么这个指令解决了我的问题,但确实如此.如果有人能够用简单的英语向我解释这一点,我将非常高兴;-)