[英]Error when running Flask application with web sockets and Gunicorn
When running my app on the local server using gunicorn, I get the following error log: 使用gunicorn在本地服务器上运行我的应用程序时,我收到以下错误日志:
[2019-06-10 20:12:20 +0200] [34160] [ERROR] Socket error processing request.
Traceback (most recent call last):
File "/Users/user/Documents/project/venv/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 135, in handle
self.handle_request(listener, req, client, addr)
File "/Users/user/Documents/project/venv/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 191, in handle_request
six.reraise(*sys.exc_info())
File "/Users/user/Documents/project/venv/lib/python3.6/site-packages/gunicorn/six.py", line 625, in reraise
raise value
File "/Users/user/Documents/project/venv/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 183, in handle_request
resp.close()
File "/Users/user/Documents/project/venv/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 409, in close
self.send_headers()
File "/Users/user/Documents/project/venv/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 329, in send_headers
util.write(self.sock, util.to_bytestring(header_str, "ascii"))
File "/Users/user/Documents/project/venv/lib/python3.6/site-packages/gunicorn/util.py", line 304, in write
sock.sendall(data)
OSError: [Errno 9] Bad file descriptor
My gunicorn configuration is the following, I executed it using gunicorn -w 4 -b 0.0.0.0:8080 uwsgi:app config=config.ini: 我的gunicorn配置如下,我使用gunicorn执行它-w 4 -b 0.0.0.0:8080 uwsgi:app config = config.ini:
[server:main]
workers = 4
worker_class = 'eventlet'
bind = '0.0.0.0:8080'
reload = False
daemon = True
timeout = 1200
port = 8080
Code for web socket connection via Flask-SocketIO: 通过Flask-SocketIO进行Web套接字连接的代码:
app = Flask(__name__)
Session(app)
socketio = SocketIO(app)
I am using Flask-SocketIO, for now I am just trying to get the socket framework working over the wsgi server without Nginx on my local machine. 我正在使用Flask-SocketIO,现在我只是想在我的本地机器上没有Nginx的情况下让套接字框架在wsgi服务器上工作。 Any suggestions on what the problem may be? 有关问题可能是什么的任何建议? Cannot piece it together from these error logs - thanks in advance for any advice! 不能从这些错误日志中拼凑出来 - 提前感谢任何建议!
I had to specify the worker as eventlet, now it is working on the local machine with gunicorn. 我不得不将worker指定为eventlet,现在它正在使用gunicorn在本地机器上工作。 I did that by running: 我这样做是通过运行:
gunicorn -w 1 -b 0.0.0.0:8080 app:app --worker-class eventlet --reload gunicorn -w 1 -b 0.0.0.0:8080 app:app --worker-class eventlet --reload
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.