I want to collect some statistical data which needs some time to process, but it is not going affect user content which is returning. I am currently doing it by first caching, then processing it with a cron job.
Is there any way to do this job immediately after returning user content?
It should be like:
def post(self):
self.response.out.write("some output")
# here user should not wait any more output
# loading should be end in user browser.
collectSomeStatistics(self)
(I am using Python 2.7)
You can use the deferred library
So your code becomes:
This then executes your function as a separate task, and the call to deferred returns immediately. Of course you won’t be able to include any results from that deferred function in the content you return to the user.