如何在python AppEngine中构建请求时获取url? [英] How to fetch a url while building a request in python AppEngine?

查看:78
本文介绍了如何在python AppEngine中构建请求时获取url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了能够在某人点击我的服务的 / show_data / url时构建获取响应,而在构建它时,我想要获取url / retrieve_data / 来自同一个服务。我怎样才能在另一个线程中启动它,这样我就可以避免我收到的DeadLineExceeded错误?我使用的是Python 2.7, threadsafe = true

In order to be able to build a get response when somebody hits /show_data/ url of my service, while I am building it I want to fetch the url /retrieve_data/ from the same service. How can I fire it up in a different thread so I can avoid the DeadLineExceeded errors I am receiving? I am using python 2.7, with threadsafe=true.

所以我对<$ c
$ b

so I have something like this for the /show_data/ handler:

def get(self):
  url = '/retrieve_data/'
  data_from_my_service = urlfetch.fetch(url)
  do_something_with_data(data_from_my_service)
  self.redirect('/')


推荐答案

您应该使用 urlfetch异步API (无需涉及线程)。

You should use urlfetch async API (no need to involve threads).

这篇关于如何在python AppEngine中构建请求时获取url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆