tornado 如何知道客户端是否结束连接

有一个tornado的脚本,当客户端请求时服务器会向某处发出一个长耗时的http请求,但是当客户端停止请求时服务端的那一个请求也就毫无意义。
如何知晓客户端的连接情况?

阅读 6.6k
3 个回答
RequestHandler.on_connection_close()
Called in async handlers if the client closed the connection.

Override this to clean up resources associated with long-lived connections. Note that this method is called only if the connection was closed during asynchronous processing; if you need to do cleanup after every request override on_finish instead.

Proxies may keep a connection open for a time (perhaps indefinitely) after the client has gone away, so this method may not be called promptly after the end user closes their connection.

http://www.tornadoweb.org/en/stable/web....

新手上路,请多包涵

客户端单方面终止连接要么就是给服务器发送finish消息,要不就得等服务器超时。要不然你单方面断了,服务器不可能一直傻等着浪费资源吧。。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题