title: Should I use Popen's wait or communicate to read stdout in subprocess in Python 3?
body: <p>I am trying to run a subprocess in Python 3 and constantly read the output.</p>
  
  <p>In the documentation for <code>subprocess</code> in Python 3 I see the following:</p>
  
  <blockquote>
    <p>Popen.wait(timeout=None)</p>
    
    <p>Wait for child process to terminate. Set and return returncode attribute.
    <strong>Warning This will deadlock when using stdout=PIPE and/or stderr=PIPE</strong>
    and the child process generates enough output to a pipe such that it
    blocks waiting for the OS pipe buffer to accept more data. Use
    communicate() to avoid that.</p>
  </blockquote>
  
  <p>Which makes me think I should use <code>communicate</code> as the amount of data from stdout is quite large.  However, reading the documentation again shows this:</p>
  
  <blockquote>
    <p>Popen.communicate(input=None, timeout=None)...</p>
    
    <p>Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached.</p>
    
    <p><strong>Note The data read is buffered in memory, so do not use this method if the data size is large or
    unlimited.</strong></p>
  </blockquote>
  
  <p>So again, it seems like there are problems with reading starndard out from subprocesses this way.  Can someone please tell me the best / safest way to run a subprocess and read all of its (potentially large amount) of stdout?</p>