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

前端 未结 2 2130
借酒劲吻你
借酒劲吻你 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:36

    Yes, your code after self.finish() will work reliably. But you can't call self.finish() twice - it will raise an exception. You can use self.finish() to close connection before all work on server is done.

    But as Cole Maclean told - don't do heavy work after finish. Look for another way to do heavy tasks in background.

提交回复
热议问题