title: How to create non-blocking continuous reading from `stdin`?
body: <p>I have a single process, which has been created like this:</p>
  
  <pre><code>p = subprocess.Popen(args   = './myapp',
                       stdin  = subprocess.PIPE,
                       stdout = subprocess.PIPE,
                       universal_newlines=True)
  </code></pre>
  
  <p>Later on, I'm trying to write to <code>p</code>'s <code>stdin</code>:</p>
  
  <pre><code>p.stdin.write('my message\n')
  </code></pre>
  
  <p>The <code>myapp</code> process has the following setup:</p>
  
  <pre><code>q = queue.Queue()
  def get_input():
      for line in iter(sys.stdin.readline, ''):
          q.put(line)
      sys.stdin.close()
  
  threading.Thread(name   = 'input-getter',
                   target = get_input).start()
  </code></pre>
  
  <p>And it is trying to read new lines continuously, like so:</p>
  
  <pre><code>try:
      print('input:', q.get_nowait())
  except Empty:
      print('no input')
  </code></pre>
  
  <p>Unfortunately the subprocess never receives any of my messages. Of course, when I use:</p>
  
  <pre><code>p.communicate('my message\n')
  </code></pre>
  
  <p>the subprocess recieves the message, but as expected, the <code>communicate</code> method closes <code>p</code>'s <code>stdin</code>, so there are no more communications going on.</p>