Open wmww opened 1 year ago
If I don't call eventlet.monkey_patch()
this problem doesn't happen, the only downside I've seen of that is that I have to send SIGINT (ctrl+C) to the python server twice to make it quit, and it shows an error on quitting:
(1595614) wsgi starting up on http://127.0.0.1:5055
(1595614) accepted ('127.0.0.1', 36448)
127.0.0.1 - - [12/Mar/2023 17:44:29] "GET /websocket HTTP/1.1" 200 0 0.001205
^Cwsgi exiting
(1595614) wsgi exited, is_accepting=True
<it's stuck here until I press Ctrl+C again>
^CException ignored in: <module 'threading' from '/usr/lib/python3.10/threading.py'>
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1567, in _shutdown
lock.acquire()
KeyboardInterrupt:
This isn't a problem if I monkey patch.
It looks like eventlet's socket implementation doesn't behave exactly like Python's original socket class. I would not recommend removing the monkey patching. Instead you can add a ping_interval, which also indirectly addresses the issue:
import eventlet
eventlet.monkey_patch()
import flask
import flask_sock
import eventlet
from eventlet import wsgi
app = flask.Flask(__name__)
app.config['SOCK_SERVER_OPTIONS'] = {'ping_interval': 25}
sock = flask_sock.Sock(app)
@sock.route('/websocket')
def websocket(ws):
ws.close()
if __name__ == '__main__':
wsgi.server(eventlet.listen(("127.0.0.1", 5055)), app)
The code (minimal example that simply closes websocket connections immediately upon creation):
To test a connection:
It gets disconnected (as we expect), but if you run it again a long error is printed in the Python output:
What's the cause of this, and can it be prevented or safely ignored?
flask version: 2.2.3 flask-sock version: 0.6.0 eventlet version: 0.33.3