【发布时间】:2019-08-23 08:19:30
【问题描述】:
当用户中断他对我的 tornado HTTP 服务器的请求时,我想处理 tornado(ver = 4.0),但我不知道这个事件何时发生。例如,我启动服务器,并运行 curl 命令来请求它,然后我在请求时中断 curl。请帮忙,谢谢!
这是我的操作
我阅读了文档并找到了on_finish 方法,但是当请求完成时会调用该方法。
# coding=u8
import time
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
print('Start %s.'%time.strftime('%F %H:%M:%S'))
time.sleep(5)
self.write('ok.')
print('Finish %s.'%time.strftime('%F %H:%M:%S'))
def on_finish(self):
"""Called after the end of a request.
Override this method to perform cleanup, logging, etc.
This method is a counterpart to `prepare`. ``on_finish`` may
not produce any output, as it is called after the response
has been sent to the client.
"""
print('Cancelled %s.'%time.strftime('%F %H:%M:%S'))
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
在处理请求期间,我如何知道客户端何时取消了它的请求?
【问题讨论】: