Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: read stdout/stderr without blocking

Reply
Thread Tools

Re: read stdout/stderr without blocking

 
 
Adriaan Renting
Guest
Posts: n/a
 
      09-12-2005
Check out the select module, for an example on how to use it:
pexpect.sourceforge.net




>>>Jacek Pop*awski <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
=?UTF-8?B?SmFjZWsgUG9wxYJhd3NraQ==?=
Guest
Posts: n/a
 
      09-12-2005
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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Non blocking socket keep blocking on read ? Serge Savoie Ruby 4 10-01-2008 03:16 PM
Re: read stdout/stderr without blocking Adriaan Renting Python 10 09-16-2005 09:07 AM
Re: read stdout/stderr without blocking Adriaan Renting Python 0 09-16-2005 07:02 AM
Re: read stdout/stderr without blocking Adriaan Renting Python 0 09-14-2005 08:09 AM
read stdout/stderr without blocking =?ISO-8859-2?Q?Jacek_Pop=B3awski?= Python 1 09-13-2005 07:25 AM



Advertisments