运行 使用网络套接字和 Gunicorn 的 Flask 应用程序时出错
Error when running Flask application with web sockets and Gunicorn
当 运行 我的应用程序在本地服务器上使用 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
我的 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
通过 Flask-SocketIO 进行网络套接字连接的代码:
app = Flask(__name__)
Session(app)
socketio = SocketIO(app)
我正在使用 Flask-SocketIO,现在我只是想让套接字框架在本地机器上没有 Nginx 的情况下在 wsgi 服务器上工作。关于问题可能是什么的任何建议?无法从这些错误日志中拼凑出来 - 在此先感谢您的任何建议!
我必须将 worker 指定为 eventlet,现在它正在使用 gunicorn 在本地机器上工作。我通过 运行:
做到了
gunicorn -w 1 -b 0.0.0.0:8080 app:app --worker-class eventlet
--reload
当 运行 我的应用程序在本地服务器上使用 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
我的 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
通过 Flask-SocketIO 进行网络套接字连接的代码:
app = Flask(__name__)
Session(app)
socketio = SocketIO(app)
我正在使用 Flask-SocketIO,现在我只是想让套接字框架在本地机器上没有 Nginx 的情况下在 wsgi 服务器上工作。关于问题可能是什么的任何建议?无法从这些错误日志中拼凑出来 - 在此先感谢您的任何建议!
我必须将 worker 指定为 eventlet,现在它正在使用 gunicorn 在本地机器上工作。我通过 运行:
做到了gunicorn -w 1 -b 0.0.0.0:8080 app:app --worker-class eventlet --reload