title: stdout.read() from finished subprocess sometimes returning empty?
body: <p>I have created a dictionary where I associate an id with a subprocess.
  Something like:</p>
  
  <pre><code>cmd = "ls"
  processes[id] = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE)
  </code></pre>
  
  <p>Then I call a method with this process map as an input, that checks which process has finished. If the process finishes, I check the process's <code>stdout.read()</code> for a particular string match.</p>
  
  <p>The issue is sometimes <code>stdout.read()</code> returns an empty value which causes issues in string matching.</p>
  
  <p>Sample Code:</p>
  
  <pre><code>#Create a map
  processes[id] = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE)
  ...
  #Pass that map to a method which checks which processes have finished
  completedProcesses(processes)
  
  def completedProcesses(processes):
      processList = []
      for id,process in processes.iteritems():
          if process.poll() is not None:
              #If some error in process stdout then print id
              verifySuccessStatus(id, processes[id])
              processList.add(id)
  
  def verifySuccessStatus(id, process):
      file=open(FAILED_IDS_FILE, 'a+')
      buffer =  process.stdout.read() #This returns empty value sometime
      if 'Error' not in buffer:
          file.write(id)
          file.write('\n')
      file.close()
  </code></pre>
  
  <p>I am new to python, I might be missing some internal functionality understanding of subprocess</p>