Take the 2-minute tour ×

I'm trying to use AsyncHTTPClient in Tornado to do multiple callouts to a "device" available over http:

def ext_call(self, params):
    device = AsyncHTTPClient()
    request = HTTPRequest(...)
    return partial(device.fetch, request)

def _do_call(self, someid):
    acall = self.ext_call(params)
    waitkey = str(someid)
    acall(callback = (yield Callback(waitkey)))
    response = yield Wait(waitkey)
    raise Return(response)

def get_device_data(self, lst):
    for someid in lst:
        r = self._do_call(someid)
        print 'response', r

But instead of HTTP responses as AsyncHTTPClient should return after .fetch, I'm getting this:

response <tornado.concurrent.TracebackFuture object at 0x951840c>

Why this is not working like examples in http://www.tornadoweb.org/en/stable/gen.html ?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Got this one solved. It appears that @coroutine has to be applied all the way down from the get/post method of your class inheriting from RequestHandler, otherwise @coroutine/yield magic does not work.

Apparently this is a case of Tornado newbiness combined with bad design on my part: according to a colleague one should not do "callback spaghetti" of nested @coroutine and yield()s, but rather move all the synchronous code out of request handler and call before or after async code it and have @coroutine call hierarchy flat rather than deep.

share|improve this answer
add comment

Your Answer


