read stdout/stderr without blocking

Grant Edwards grante at visi.com
Tue Sep 13 10:27:04 EDT 2005


On 2005-09-13, Jacek Pop³awski <jpopl at interia.pl> wrote:

>>>>        ready = select.select(tocheck, [], [], 0.25) ##continues after 0.25s
>>>>        for file in ready[0]:
>>>>            try:
>>>>                text = os.read(file, 1024)
>>>
>>>How do you know here, that you should read 1024 characters?
>>>What will happen when output is shorter?
>> 
>> It will return however much data is available.
>
> My tests showed, that it will block.

You're right.  I must have been remembering the behavior of a
network socket.  Apparently, you're supposed to read a single
byte and then call select() again.  That seems pretty lame.

-- 
Grant Edwards                   grante             Yow!  Psychoanalysis?? I
                                  at               thought this was a nude
                               visi.com            rap session!!!



More information about the Python-list mailing list