How to fetch a url while building a request in pyt

2019-08-14 04:54发布

This question already has an answer here:

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.

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('/')

1条回答
家丑人穷心不美
2楼-- · 2019-08-14 05:11

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

查看更多
登录 后发表回答