I have the following python code, which runs fine on Linux, but stalls forever waiting for feedback on Windows.  I am running Python 2.6.6 on Linux, python 2.7.2 on Windows, and am using the tee program from Cygwin-x86_64.  If the problem doesn't seem to be reproducible on someone else's windows build, I can give more details about my setup.  Here is the script:
from __future__ import with_statement
# from http://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python
import sys
from subprocess import PIPE, STDOUT
import subprocess, time
from threading  import Thread
import os, subprocess
import re, time
from Queue import Queue, Empty
ON_POSIX = 'posix' in sys.builtin_module_names
def enqueue_output(out, queue):
    for line in iter((lambda : out.read(1)), b''):
        # print('0: %s' % line)
        queue.put(line)
    out.close()
class Popen_async(object):
    """Allows non-blocking reading from a Popen, by
    p = Popen_async(['myprogram.exe'], stdout=PIPE, stderr=PIPE)
    try:  line = p.stdout.get_nowait() # or p.stdout.get(timeout=.1)
    except Empty:
        print('no output yet')
    else: # got line
    """
    def __init__(self, *args, **kwargs):
        self._p = subprocess.Popen(*args, bufsize=1, close_fds=ON_POSIX, **kwargs)
        self.stdout = Queue()
        self.stderr = Queue()
        self._tout = Thread(target=enqueue_output, args=(self._p.stdout, self.stdout))
        # self._terr = Thread(target=enqueue_output, args=(self._p.stderr, self.stderr))
        self._tout.daemon = True # thread dies with the program
        # self._terr.daemon = True # thread dies with the program
        self._tout.start()
        # self._terr.start()
        self.stdin = self._p.stdin
        time.sleep(0.1)
def get_all_nowait_iter(q):
    try:
        while True:
            yield q.get_nowait()
    except Empty:
        pass
def get_all_nowait(q):
    return ''.join(get_all_nowait_iter(q))
def get_all_semiwait_iter(q):
    def log_and_return(val):
        print(val)
        return val
    try:
        # this is blocking; TODO(jgross): Figure out how to get coqtop
        # to tell us if it's finished computing
        yield log_and_return(q.get(True))
        while True:
            yield log_and_return(q.get(True, 0.1))
    except Empty:
        pass
def get_all_semiwait(q):
    return ''.join(get_all_semiwait_iter(q))
def run(filename='log'):
    p = Popen_async(['tee', filename], stdout=PIPE, stderr=STDOUT, stdin=PIPE)
    time.sleep(1)
    for i in range(10):
        print('Write: %s' % (str(i) + '\n'))
        p.stdin.write(str(i) + '\n')
        print('Wait to read...')
        stdout = get_all_semiwait(p.stdout)
        print('Read: %s' % stdout)
if __name__ == '__main__':
    run()
What's the cause of the difference in behavior between Windows and Linux?
