在我的应用程序中,我在页面加载时使用 Jquery 触发 Ajax 获取请求。如果调用花费了异常长的时间,则用户可能会在其标准浏览会话期间导航离开初始页面。最终,这个 ajax 调用完成并返回一个响应。问题是,此时用户已经离开了页面,并且没有任何东西在监听响应。发生这种情况时,我会在日志中收到此异常。
----------------------------------------
Exception happened during processing of request from ('98.x.x.x', 36495)
Traceback (most recent call last):
File "M:\Python2.7\App\lib\SocketServer.py", line 582, in process_request_thread
self.finish_request(request, client_address)
File "M:\Python2.7\App\lib\SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "M:\Python2.7\App\lib\site-packages\django\core\servers\basehttp.py", line 139, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "M:\Python2.7\App\lib\SocketServer.py", line 640, in __init__
self.finish()
File "M:\Python2.7\App\lib\SocketServer.py", line 693, in finish
self.wfile.flush()
File "M:\Python2.7\App\lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
----------------------------------------
我怎样才能防止这种情况发生?
例外中列出的所有文件都不是我的代码。