When I get a GET request from a user, I send them the response and then spend maybe a second logging stuff about that request. Is there a way to close the connection when I have the response ready, but continue doing that logging part, so that the user wouldn't have to wait for it to complete?
+3
A:
From the Google App Engine docs for the Response object:
App Engine does not support sending data to the user's browser before exiting the handler. Some web servers use this technique to "stream" data to the user's browser over a period of time in response to a single request. App Engine does not support this streaming technique.
So there's no easy way. If you have a bundle of data that you can pass to a longer-running "process and log" method, try using the deferred library. Note that this will requiring bundling your data up and sending it to the task queue to do your processing and logging, so
- you may not save much time, and
- the results may not look much like you'd want - for example, you'd be logging from a different request, so might need to radically alter the logging
Still, you could try.
Blair Conrad
2010-02-14 15:11:37
A:
You have two options:
- Use the Task Queue API. Enqueueing a task should be fast, so long as you have less than 10k of data (which is the limit on a Task Queue payload).
- Use the 'sneaky' trick described by Rafe in this video to do processing after the response completes.
Nick Johnson
2010-02-15 11:13:31