title: Print realtime output of subprocess in jupyter notebook
body: <p>In my file 'wrapper.py' I call a subprocess and print its output to stdout at realtime . This works just fine if I call the python script from the console. However, when calling it from a jupyter notebook the code hangs at the line proc.stdout.readline(). All previous print statements work fine..</p>
  <pre><code>proc = subprocess.Popen([&quot;calc&quot;, &quot;input.txt&quot;], cwd=__dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  while True:
      out = proc.stdout.readline().decode(&quot;utf-8&quot;)
      err = proc.stderr.readline().decode(&quot;utf-8&quot;)
      if out == '' and err == '' and proc.poll() is not None:
          break
      if out:
          print(&quot;::::%s&quot;%(out), end='')
      if err:
          print(&quot;::::%s&quot;%(err), end='', file=sys.stderr)
  rc = proc.poll()
  print(&quot;---&gt; returns %s&quot;%(rc))
  </code></pre>
  <p>Does anyone have an idea on how to fix this?</p>