Tornado: Can I run code after calling self.finish() in an asynchronous RequestHandler?

前端 未结 2 2133
借酒劲吻你
借酒劲吻你 2021-02-07 19:00

I\'m using Tornado. I have a bunch of asynchronous request handlers. Most of them do their work asynchronously, and then report the result of that work back to the user. But

2条回答
  •  醉酒成梦
    2021-02-07 19:24

    Yes, you can.

    You have to define on_finish method of your RequestHandler. This is a function run after the request finished and has sent the response to client.

    RequestHandler.on_finish()

    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.

提交回复
热议问题