Popen stdout reading pipe, deadlock using sleep
Question: Well, I have two scripts. The a.py which prints the output of the b.py script
as follows:

    
    
    #a.py
    from subprocess import Popen, PIPE, STDOUT
    
    p = Popen(['/Users/damian/Desktop/b.py'], shell=False, stdout=PIPE, stderr=STDOUT)
    
    while p.poll() is None:
        print p.stdout.readline()
    
    
    #b.py
    #!/usr/bin/env python
    import time
    
    while 1:
        print 'some output'
        #time.sleep(1)
    

This works.But, Why do my scripts deadlock when I uncomment the time.sleep()
line?


Answer: Your output is probably buffered. Add a
[.flush()](http://docs.python.org/library/stdtypes.html#file.flush) for stdout
to clear it:

    
    
    import sys
    import time
    
    while 1:
        print 'someoutput'
        sys.stdout.flush()
        time.sleep(1)
    

