webapp.RequestHandler based Handlers can override initialize () to carry out setup. Is there a similar finalize() ? Could I override del() to achieve this ?
Basically, I am looking to making some journal entries after the post/get functions have completed such that this is not in the critical path of the Response back to the browser..
I could either (1) do this in this ‘finalize’ call assuming it is called after the Response is flushed to the browser or (2) push the work on a separate thread-pool-queue. If there is a way to do former, that would be a lot easier/simpler.
Thanks.
You could override
__del__, but this is dangerous (can introduce GC loops and uncollectable objects), and doesn’t gain you anything.You don’t gain anything because the App Engine runtime does not return the response to the user until the WSGI application has returned, which does not happen until all user code has finished executing. Likewise, threads on a frontend cannot run longer than the scope of the request for which they were created.
If you want to do work outside the scope of a request, you should use the Task Queue.