In the docs there is an async example that pulls the count of Bret's
Friendfeed stream. The last line in the docs calls finish(), which
ends the async connection as expected. I, however, don't want to end
the connection, but would prefer to flush the buffered string to the
client, and keep the connection open, so, I replace finish() with
flush():
class MainHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
http = httpclient.AsyncHTTPClient()
http.fetch("
http://friendfeed-api.com/v2/feed/bret",
callback=self.async_callback(self.on_response))
print 'done with get'
def on_response(self, response):
if response.error: raise tornado.web.HTTPError(500)
json = tornado.escape.json_decode(response.body)
self.write("Fetched %d entries from the FriendFeed API" %
len(json['entries']))
self.flush() #THIS IS THE LINE I REPLACED
When I run curl
http://localhost:8888/ with this example, I never see
the text and count written to the terminal, although the connection
remains open. Is this a bug with flush() or is there another way to
really flush the written content to the client?
Thanks in advance.
Stu