title: Python Popen writing to stdin not working when in a thread
body: <p>I'm trying to write a program that simultaneously reads and writes to a process's std(out/in) respectively. However, it seems that writing to a program's stdin in a thread does not work. Here's the relevant bits of code:</p>
  
  <pre><code>import subprocess, threading, queue
  
  def intoP(proc, que):
      while True:
          if proc.returncode is not None:
              break
          text = que.get().encode() + b"\n"
          print(repr(text))      # This works
          proc.stdin.write(text) # This doesn't.
  
  
  que = queue.Queue(-1)
  
  proc = subprocess.Popen(["cat"], stdin=subprocess.PIPE)
  
  threading.Thread(target=intoP, args=(proc, que)).start()
  
  que.put("Hello, world!")
  </code></pre>
  
  <p>What's going wrong, and is there a way to fix it?</p>
  
  <p>I'm running python 3.1.2 on Mac OSX, it's confirmed that it works in python2.7.</p>