title: python subprocess callback when updated output
body: <p>I am using tornado. I hope the following is easy to understand, It's spawning a tcproute process and sending the output to the websocket's other end.</p>
  
  <pre><code>class TracerouteHandler(tornado.websocket.WebSocketHandler):
    def open(self,ip):
      p = subprocess.Popen(['traceroute',ip],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      while p.poll() is None: #running
        line=p.stdout.readline()
        if line!=None and len(line)&gt;0:
          self.write_message(json.dumps({'stdout':line})) 
      self.write_message(json.dumps({'stdout':'Done! For red marked ip addresses, the location couldn\'t be determined with &lt;a href="http://hostip.info"&gt;hostip.info&lt;/a&gt;. If you know the correct location, please update it there.'}))
  </code></pre>
  
  <p>The problem is that due to the <code>while p.poll() is None</code> loop, tornado blocks. Also, if there's nothing in p.stdout to read, the <code>p.stdout.readline</code> blocks. So I'd like to have some sort of callback mechanism that gets fired when I have something new in <code>p.stdout</code>. How do I do that?</p>