开发者

Indicating that GET response is complete w/ Python AppEngine

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开发者_Go百科 wait for it to complete?


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

  1. you may not save much time, and
  2. 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.


You have two options:

  1. 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).
  2. Use the 'sneaky' trick described by Rafe in this video to do processing after the response completes.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜