0

I am now implementing the async query in tornado, and facing some problems. My code always returns DummyFuture does not support blocking for results. Googled some posts and it's seems I didn't add the return response into Future. Try to modify my code but it still returns the same error. Please help to check my code.

from tornado import httpclient

query_url = 'https://some_url.com'
http_client = httpclient.AsyncHTTPClient()

def request(query_url):
    resp = yield(http_client.fetch(query_url, method="GET"))
    raise Return(resp.body)

response = request(query_url)
do_something_for_response(response)

My expected response should be a json format and in the function do_something_for_response, it handles the json and return to outside.

Thanks for your help.

Jimmy Lin
  • 1,481
  • 6
  • 27
  • 44
  • No, sorry, I can't change the framework. – Jimmy Lin Mar 19 '18 at 09:33
  • 1
    you need to make `request` a coroutine and the whole chain of calls which leads to `request` too. Also a `ioloop` is required to make async calls work correctly. Try to use https://github.com/tornadoweb/tornado/blob/master/demos/webspider/webspider.py as a start. – Gennady Kandaurov Mar 20 '18 at 09:25
  • Possible duplicate of [Tornado: DummyFuture does not support blocking for results](https://stackoverflow.com/questions/42425318/tornado-dummyfuture-does-not-support-blocking-for-results) – Ben Darnell Mar 21 '18 at 04:05
  • @GennadyKandaurov, do you mean that I need to add `@gen.coroutine` before every functions from beginning to the end of a query? – Jimmy Lin Mar 21 '18 at 06:11

0 Answers0