I
I
Imbolc2014-02-11 16:57:30
Python
Imbolc, 2014-02-11 16:57:30

How does tornado.web.RequestHandler.flush work?

The server looks like this:

from tornado import ioloop, web, gen


class MainHandler(web.RequestHandler):
    @gen.coroutine
    def get(self):
        self.write('1' * 1024)
        self.flush(callback=(yield gen.Callback('flush')))
        yield gen.Wait('flush')
        print 'First chunk sent'


        self.write('2' * 1024)
        self.flush(callback=(yield gen.Callback('flush')))
        yield gen.Wait('flush')
        print 'Second chunk sent'
        self.finish()


application = web.Application([
    (r"/", MainHandler),
])


if __name__ == "__main__":
    application.listen(8000)
    ioloop.IOLoop.instance().start()

Client like this:
import urllib2
urllib2.urlopen('http://127.0.0.1:8000/').close()

After the request in the server console I see:
First chunk sent
Second chunk sent

I wish I didn't see anything there. Where am I wrong?
UP: @rSedoy explained the situation, details in the comments

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question