Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: read stdout/stderr without blocking (http://www.velocityreviews.com/forums/t348992-re-read-stdout-stderr-without-blocking.html)

Adriaan Renting 09-12-2005 08:49 AM

Re: read stdout/stderr without blocking
 
Check out the select module, for an example on how to use it:
pexpect.sourceforge.net




>>>Jacek Pop*awski <jpopl@interia.pl> 09/12/05 10:07 am >>>

Popen from subprocess module gives me access to stdout, so I can read
it. Problem is, that I don't know how much data is available... How can
I read it without blocking my program?

example:
--------------------------------------------------------------------
import subprocess
import time

command="ls -l -R /"

p=subprocess.Popen(command,shell=True,stdout=subpr ocess.PIPE,stderr=subprocess.PIPE)

while (p.poll()==None):
print "."
r=p.stdout.read()
--------------------------------------------------------------------

when you comment out read() - you will notice that loop is working, with
read() loop is blocked
Of course I don't need to read() inside loop, but... if output is very
long (like from "make") and I don't read from stdout - command will
block itself! I tried to increase bufsize, but it didn't help.

Is there a way to read only available data from stdout/stderr?
Is there a way to not block Popen command without reading stdout/stderr?
--
http://mail.python.org/mailman/listinfo/python-list


=?UTF-8?B?SmFjZWsgUG9wxYJhd3NraQ==?= 09-12-2005 11:14 AM

Re: read stdout/stderr without blocking
 
Adriaan Renting wrote:
> Check out the select module, for an example on how to use it:
> pexpect.sourceforge.net


Two problems:
- it won't work on Windows (Cygwin)
- how much data should I read after select? 1 character? Can it block if
I read 2 characters?


All times are GMT. The time now is 04:36 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57