Re: Non-blocking read with popen subprocess

2009-07-31 Thread birdsong
On Jul 30, 7:30 pm, Jonathan Gardner wrote: > On Jul 30, 5:24 pm, Dhanesh wrote: > > > > > how can I we have a non blocking read ? > > Seehttp://docs.python.org/library/popen2.html#flow-control-issues > > Note well: In the non-blocking world, you have to use select(

Re: Non-blocking read with popen subprocess

2009-07-31 Thread Javier Collado
# > > I observed that python scripts blocks at stdout read on the other hand > when I do not create a child stdout PIPE  say  " stdout=None" , things > seems to be working fine. > > how can I we have a non blocking read ? > And why does stdout blo

Re: Non-blocking read with popen subprocess

2009-07-31 Thread Piet van Oostrum
>>>>> Jonathan Gardner (JG) wrote: >JG> On Jul 30, 5:24 pm, Dhanesh wrote: >>> >>> how can I we have a non blocking read ? >JG> See http://docs.python.org/library/popen2.html#flow-control-issues >JG> Note well: In the non-blocking world, y

Re: Non-blocking read with popen subprocess

2009-07-30 Thread Jonathan Gardner
On Jul 30, 5:24 pm, Dhanesh wrote: > > how can I we have a non blocking read ? See http://docs.python.org/library/popen2.html#flow-control-issues Note well: In the non-blocking world, you have to use select() or poll () to get your job done. You may want to look at "communi

Non-blocking read with popen subprocess

2009-07-30 Thread Dhanesh
## I observed that python scripts blocks at stdout read on the other hand when I do not create a child stdout PIPE say " stdout=None" , things seems to be working fine. how can I we have a non blocking read ? And why does stdout block even where data is available to be

Re: Non blocking read from stdin on windows.

2004-12-25 Thread Noam Raphael
You can always have a thread which continually reads stdin and stores it in a string, or better, in a cStringIO.StringIO object. Then in the main thread, you can check whether something new has arrived. This, of course will work on all platforms. I hope this helped a bit, Noam -- http://mail.py

Non blocking read from stdin on windows.

2004-12-25 Thread barr
Hi Can any one help. I am trying to write a python scipt that takes input as args and/or as piped input ( possibly the output of another program). I want to read stdin ( the piped in stuuff ) whcih might be empty without the script blocking if it is empty. I understand it is possible to do unde

Re: non blocking read()

2004-12-02 Thread Greg Ewing
Donn Cave wrote: Yes, this looks right to me, but I think we're talking about os.read(), not fileobject.read(). Indeed, you shouldn't be mixing select() with buffered io, or all kinds of bad things can happen. Everything I said applies to OS-level reads and writes, not stdio-level ones. -- Greg Ewi

Re: non blocking read()

2004-12-02 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Greg Ewing <[EMAIL PROTECTED]> wrote: > Donn Cave wrote: > > If we are indeed talking about a pipe or something that > > really can block, and you call fileobject.read(1024), > > it will block until it gets 1024 bytes. > > No, it won't, it will block until *some*

Re: non blocking read()

2004-12-02 Thread Steve Holden
Gustavo Córdova Avila wrote: Steve Holden wrote: Gustavo Córdova Avila wrote: Actually the op did mention that he wanted to monitor files. As was pointed out to me when I made the same assertion, he actually said "file object which is stdin" or something like that, which means the object could b

Re: non blocking read()

2004-12-02 Thread Gustavo Córdova Avila
Steve Holden wrote: Gustavo Córdova Avila wrote: Actually the op did mention that he wanted to monitor files. As was pointed out to me when I made the same assertion, he actually said "file object which is stdin" or something like that, which means the object could be a socket, a pipe, a file, a

Re: non blocking read()

2004-12-02 Thread Steve Holden
Gustavo Córdova Avila wrote: Donn Cave wrote: Depends. I don't believe the original post mentioned that the file is a pipe, socket or similar, but it's kind of implied by the use of select() also mentioned. It's also kind of implied by use of the term "block" - disk files don't block. If we are in

Re: non blocking read()

2004-12-02 Thread Gustavo Córdova Avila
Donn Cave wrote: Depends. I don't believe the original post mentioned that the file is a pipe, socket or similar, but it's kind of implied by the use of select() also mentioned. It's also kind of implied by use of the term "block" - disk files don't block. If we are indeed talking about a pipe or

Re: non blocking read()

2004-12-02 Thread Pierre Barbier de Reuille
Steve Holden a écrit : Donn Cave wrote: In article <[EMAIL PROTECTED]>, Gustavo Córdova Avila <[EMAIL PROTECTED]> wrote: David Bolen wrote: Jp Calderone <[EMAIL PROTECTED]> writes: def nonBlockingReadAll(fileObj): bytes = [] while True: b = fileObj.read(1024)

Re: non blocking read()

2004-12-01 Thread Greg Ewing
Steve Holden wrote: When access is made to a file object in non-blocking mode it will return whatever data there are immediately available in the buffers, up to the number of bytes requested. If the buffers are currently empty the process will generate an error Are you sure that's right? If so,

Re: non blocking read()

2004-12-01 Thread Greg Ewing
Donn Cave wrote: If we are indeed talking about a pipe or something that really can block, and you call fileobject.read(1024), it will block until it gets 1024 bytes. No, it won't, it will block until *some* data is available, and then return that (up to a maximum of 1024). If the fd has just been

Re: non blocking read()

2004-12-01 Thread Steve Holden
Donn Cave wrote: In article <[EMAIL PROTECTED]>, Gustavo Córdova Avila <[EMAIL PROTECTED]> wrote: David Bolen wrote: Jp Calderone <[EMAIL PROTECTED]> writes: def nonBlockingReadAll(fileObj): bytes = [] while True: b = fileObj.read(1024) bytes.append(b)

Re: non blocking read()

2004-12-01 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Gustavo Córdova Avila <[EMAIL PROTECTED]> wrote: > David Bolen wrote: > > >Jp Calderone <[EMAIL PROTECTED]> writes: > > > >>def nonBlockingReadAll(fileObj): > >>bytes = [] > >>while True: > >>b = fileObj.read(1024) > >>

Re: non blocking read()

2004-12-01 Thread Gustavo Córdova Avila
David Bolen wrote: Jp Calderone <[EMAIL PROTECTED]> writes: def nonBlockingReadAll(fileObj): bytes = [] while True: b = fileObj.read(1024) bytes.append(b) if len(b) < 1024: break return ''.join(bytes) Wouldn't this still block

Re: non blocking read()

2004-12-01 Thread Jp Calderone
On 01 Dec 2004 15:55:18 -0500, David Bolen <[EMAIL PROTECTED]> wrote: >Jp Calderone <[EMAIL PROTECTED]> writes: > > > def nonBlockingReadAll(fileObj): > > bytes = [] > > while True: > > b = fileObj.read(1024) > > bytes.append(b) > > if len(b)

Re: non blocking read()

2004-12-01 Thread David Bolen
Jp Calderone <[EMAIL PROTECTED]> writes: > def nonBlockingReadAll(fileObj): > bytes = [] > while True: > b = fileObj.read(1024) > bytes.append(b) > if len(b) < 1024: > break > return ''.join(bytes) Wouldn't this still

Re: non blocking read()

2004-12-01 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Uwe Mayer <[EMAIL PROTECTED]> wrote: > Hi, > > I use select() to wait for a file object (stdin) to become readable. In that > situation I wanted to read everything available from stdin and return to > the select statement to wait for more. > > However, the file o

Re: non blocking read()

2004-12-01 Thread Jp Calderone
On Wed, 01 Dec 2004 19:39:45 +0100, Uwe Mayer <[EMAIL PROTECTED]> wrote: >Hi, > > I use select() to wait for a file object (stdin) to become readable. In that > situation I wanted to read everything available from stdin and return to > the select statement to wait for more. > > However, the file

non blocking read()

2004-12-01 Thread Uwe Mayer
Hi, I use select() to wait for a file object (stdin) to become readable. In that situation I wanted to read everything available from stdin and return to the select statement to wait for more. However, the file object's read method blocks if the number of bytes is 0 or negative. Is there no way