我正在编写代码来参加服务。我收到对特定服务的 POST 请求并开始处理。整个过程相当简单;我循环请求中的项目并将每个项目添加到数据库中。当我必须处理很多项目并且循环需要大约三分钟才能完成时,就会出现问题,然后当我尝试响应时:
status = '200 OK'
headers = [('Content-type', 'application/json'),('Access-Control-Allow-Origin','*')]
start_response(status, headers)
return json.dumps(response)
我收到此错误:
Exception happened during processing of request from ('XXX.XXX.XXX.XXX', 49172)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/local/lib/python2.7/SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "/usr/local/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/lib/python2.7/SocketServer.py", line 640, in __init__
self.finish()
File "/usr/local/lib/python2.7/SocketServer.py", line 693, in finish
self.wfile.flush()
File "/usr/local/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
我不知道这是否有帮助,但 POST 请求是从浏览器到不同域的转发 POST(这就是为什么使用 Access-Control-Allow-Origin)并且对数据库的所有访问都是使用单个使用SQLAlchemy与数据库交互的对象(类似于Java EE DAO模式)。
如何避免此错误?