Google App Engine Python 上的异步 http 请求
有谁知道如何从 Google App Engine 发出 http 请求而不等待响应? 它应该像带有 http 的推送数据,没有响应延迟。
Does anybody know how to make http request from Google App Engine without waiting a response?
It should be like a push data with http without latency for response.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为AppEngine 文档的这一部分就是您的意思寻找。
I think that this section of the AppEngine docs is what you are looking for.
使用任务队列。如果您只是推送数据,则等待响应是没有意义的。
Use the taskqueue. If you're just pushing data, there's no sense in waiting for the response.
您可以做的就是在请求处理程序中将接收到的任何数据放入任务队列(使用 deferred库)。一旦任务成功入队,您就可以返回“200 OK”响应并为下一次推送做好准备。
What you could do is in the request handler enqueue a task with whatever data was received (using the deferred library). As soon as the task has been enqueued successfully you can return a '200 OK' response and be ready for the next push.
我之前通过设置执行 URLFetch 并为截止时间参数设置非常低的值来完成此操作。我将 0.1 作为我的值,即 100ms。您还需要将 URLFetch 包装在 try/catch 中,因为请求会超时。
I've done this before by setting doing a URLFetch and setting a very low value for the deadline parameter. I put 0.1 as my value, so 100ms. You need to wrap the URLFetch in a try/catch also since the request will timeout.