Tornado: Can I Run Code After Calling Self.finish() In An Asynchronous Requesthandler?
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 I ha
Solution 1:
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.
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.
Solution 2:
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.
Post a Comment for "Tornado: Can I Run Code After Calling Self.finish() In An Asynchronous Requesthandler?"