我正在使用Python Flask来构建我的应用程序。但是最近我在请求API耗时的数据时遇到了错误,只是一些物理服务器硬件数据,但有时可能需要10多秒。
File "c:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "c:\Python27\lib\SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "c:\Python27\lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "c:\Python27\lib\SocketServer.py", line 657, in __init__
self.finish()
File "c:\Python27\lib\SocketServer.py", line 716, in finish
self.wfile.close()
File "c:\Python27\lib\socket.py", line 283, in close
self.flush()
File "c:\Python27\lib\socket.py", line 307, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
socket.error: [Errno 10053]
我发现我的http请求客户端将以超时5秒断开连接。当我删除timeout参数时,此错误不再存在。事实上,API每5秒调用一次,因此如果任务本身花费的时间超过5秒,则后面的请求会卡住并卡住。我的问题是,在处理相同的请求时,可以配置flask来中止传入的请求吗?或者对此类型的任何建议都很欣赏。 TIA。 :)