我有一个运行中的Flask-SocketIO服务器,但它不适用于Gunicorn。服务器的相关部分如下所示:
def main(env, resp):
app = Flask(__name__,
static_url_path='',
static_folder='dist',
template_folder='dist')
socketio = SocketIO(app)
@app.route('/')
def home():
return app.send_static_file('index.html')
# socketio.run(app, host='0.0.0.0', port=8000) I comment this out when using Gunicorn because otherwise it tries to run the process twice and throws an error.
我正在使用eventlet,并按照Flask-SocketIO文档here中的描述运行以下命令:
gunicorn --worker-class eventlet -b 0.0.0.0:8000 -w 1 index:main
gunicorn过程开始正常,但是当我导航到页面时,出现以下服务器错误:
Error handling request /
Traceback (most recent call last):
File "/home/myusername/.local/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 55, in handle
self.handle_request(listener_name, req, client, addr)
File "/home/myusername/.local/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 113, in handle_request
for item in respiter:
TypeError: 'NoneType' object is not iterable
我找不到有关此错误的任何信息,将不胜感激。
我必须从main()返回应用程序。 main中的其他参数是不必要的。我还添加了一个wsgi文件:
from index import main
if __name__ == '__main__':
main()
else:
gmain = main()
然后使用该文件gunicorn -k eventlet -b 0.0.0.0:8000 -w 1 wsgi:gmain
来运行古尼康,并且可以正常工作。 Seleniumwire引发了错误,但这不在此问题的范围内。