title: sys.stdin.read() in subprocess never returning
body: <p>I'm trying to understand subprocess.Popen and subprocess.PIPE. While doing so, I created three small scripts.</p>
  
  <p>The goal of this exercise is, to print data with one script, read it from the other and echo this back to the first script.</p>
  
  <p>The problem is, that the last sys.stdin.read() prevents the entire code from working properly.</p>
  
  <p><strong>test.py</strong></p>
  
  <pre><code>#!/usr/bin/python3
  
  from subprocess import Popen, PIPE
  
  proc1 = Popen(["python3","script1.py"], stdin=PIPE, stdout=PIPE)
  proc2 = Popen(["python3","script2.py"], stdin=PIPE, stdout=PIPE)
  
  first_output = proc1.stdout.read()
  
  print("[test.py:] " + str(first_output))
  
  proc2.stdin.write(first_output)
  proc2.stdin.flush()
  proc2.stdin.close()
  
  answer = proc2.stdout.read()
  
  print("[test.py:] " + str(answer))
  
  proc1.stdin.write(answer)
  </code></pre>
  
  <p><strong>script1.py</strong></p>
  
  <pre><code>import sys
  
  sys.stdout.write("Hello world")
  sys.stdout.flush()
  
  answer = str(sys.stdin.read())
  </code></pre>
  
  <p>The last line in script1.py <code>answer = str(sys.stdin.read())</code> causes the entire program to get stuck. If I comment it out, everything works fine.</p>
  
  <p>Why is that so and why am I not able to communicate any further? I didn't find an answer yet.</p>
  
  <p><strong>script2.py</strong></p>
  
  <pre><code>import sys
  
  input_read = str(sys.stdin.read())
  
  sys.stdout.write("[script2.py:] " + input_read + " input read")
  sys.stdout.flush()
  </code></pre>