title: How can I serve a (never ending) system call with Tornado
body: <p>For instance, suppose I have this code:</p>
  
  <pre><code>def dump():
      tcpdump = subprocess.Popen("tcpdump -nli any", 
          stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
      outputfile = tcpdump.stdout
  
      for line in outputfile:
          print line,
  </code></pre>
  
  <p>How can I serve the output of such to the browser?
  Since there is no stopping point, I have no idea where to hook with the polling loop.
  More than that, as print line works (I see lines dumped on the terminal), browser do not get the very same lines, see below:</p>
  
  <pre><code>class TCPDumpHandler(tornado.web.RequestHandler):
      def get(self):
          self.write("&lt;form method='post' action='/log'&gt;&lt;input type='submit'&gt;&lt;/form&gt;")
  
      @tornado.web.asynchronous
      def post(self):
          tcpdump = subprocess.Popen("tcpdump -nli any", 
              stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
          outputfile = tcpdump.stdout
  
          for line in outputfile:
              print line,
              self.write(line)
  
          self.finish()
  </code></pre>