Server processing time more than 60s锛宼he error occurred
127.0.0.1 - - [29/Nov/2017 10:54:29] "POST /socket.io/?EIO=3&transport=polling&t=M05idCN&sid=0d462cd6c2154e74bb80be86921089bf HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
File "D:Program FilesPython35libsite-packageswerkzeugserving.py", line 209, in run_wsgi
execute(self.server.app)
File "D:Program FilesPython35libsite-packageswerkzeugserving.py", line 197, in execute
application_iter = app(environ, start_response)
File "D:Program FilesPython35libsite-packagesflaskapp.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "D:Program FilesPython35libsite-packagesflask_socketio__init__.py", line 42, in __call__
start_response)
File "D:Program FilesPython35libsite-packagesengineiomiddleware.py", line 47, in __call__
return self.engineio_app.handle_request(environ, start_response)
File "D:Program FilesPython35libsite-packagessocketioserver.py", line 360, in handle_request
return self.eio.handle_request(environ, start_response)
File "D:Program FilesPython35libsite-packagesengineioserver.py", line 290, in handle_request
socket = self._get_socket(sid)
File "D:Program FilesPython35libsite-packagesengineioserver.py", line 421, in _get_socket
raise KeyError('Session is disconnected')
KeyError: 'Session is disconnected'
Invalid session 0d462cd6c2154e74bb80be86921089bf
test code:
flask.zip
This isn't a bug, event handlers are assumed to be quick so that the system does not block. If you really need to have these long event handlers, then consider using the async_handlers=True option.
Thank you for the help! I used start_background_task() to solve the problem.
@miguelgrinberg when using the eventlet, I got this error:
2017-12-01 14:58:22,295 - engineio - INFO - ae7433cdd2df47b8aecc6d2545b834fb: Client is gone, closing socket
2017-12-01 14:58:22,299 - socketio - INFO - emitting event "compare-result-d500c3dc-d664-11e7-bdab-945330cf466a" to all [/]
2017-12-01 14:58:22,303 - engineio - INFO - ae7433cdd2df47b8aecc6d2545b834fb: Received packet PING data None
2017-12-01 14:58:22,305 - engineio - ERROR - Receive error
Traceback (most recent call last):
File "D:\Program Files\Python35\lib\site-packages\engineio\socket.py", line 210, in _websocket_handler
self.receive(pkt)
File "D:\Program Files\Python35\lib\site-packages\engineio\socket.py", line 54, in receive
self.send(packet.Packet(packet.PONG, pkt.data))
File "D:\Program Files\Python35\lib\site-packages\engineio\socket.py", line 68, in send
raise IOError('Socket is closed')
OSError: Socket is closed
def img_convert():
# Image processing
It seems start_background_task(target=img_convert) not a new thread. when img_convert excuting,I did not see the logging for PING/PONG
when using werkzeug, it's OK.
Please help, thanks!
@zuifengwuchou you can have tasks that use the CPU for a long time, that blocks the whole thing. Eventlet uses cooperative multi-tasking, tasks must be either short, or if they are long should call sleep(0) regularly to give other tasks a chance to run.
This isn't a bug, event handlers are assumed to be quick so that the system does not block. If you really need to have these long event handlers, then consider using the
async_handlers=Trueoption.
Fantastic !!! Thanks :)
Most helpful comment
@zuifengwuchou you can have tasks that use the CPU for a long time, that blocks the whole thing. Eventlet uses cooperative multi-tasking, tasks must be either short, or if they are long should call
sleep(0)regularly to give other tasks a chance to run.