Re: read stdout/stderr without blocking

2005-09-16 Thread Jacek Popławski
Donn Cave wrote: > I don't recall the beginning of this thread, so I'm not sure > if this is the usual wretched exercise of trying to make this > work on both UNIX and Windows, It is used in "test framework" which runs on Linux, Windows (Cygwin) and QNX. I can't forget about Windows. -- http://

Re: read stdout/stderr without blocking

2005-09-16 Thread Adriaan Renting
Great reply, I had just mixed Pexpect and subProcess code until I'd got something that worked, you can actually explain my code better a I can myself. I find it quite cumbersome to read stdout/strerr separately, and to be able to write to stdin in reaction to either of them, but at least on Lin

Re: read stdout/stderr without blocking

2005-09-15 Thread Peter Hansen
Donn Cave wrote: > Peter Hansen <[EMAIL PROTECTED]> wrote: >>Jacek Pop³awski wrote: >>>My tests showed, that it will block. >> >>Not if you use non-blocking sockets, as I believe you are expected to >>when using select(). > > On the contrary, you need non-blocking sockets only if > you don't use

Re: read stdout/stderr without blocking

2005-09-15 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Peter Hansen <[EMAIL PROTECTED]> wrote: > Jacek Pop³awski wrote: > > Grant Edwards wrote: > > > >> On 2005-09-12, Jacek Pop?awski <[EMAIL PROTECTED]> wrote: > >> > ready = select.select(tocheck, [], [], 0.25) ##continues > after 0.25s >

Re: read stdout/stderr without blocking

2005-09-14 Thread Adriaan Renting
Please note that popen uses pipes, which are block devices, not character devices, so the writes will be done in blocks instead of characters/lines, (you can only read something _after_ the application at the other end of the pipe has done a flush or written 8192 bytes. When reading from a pty

Re: read stdout/stderr without blocking

2005-09-14 Thread Adriaan Renting
>>>Jacek Pop*awski <[EMAIL PROTECTED]> 09/13/05 9:23 am >>> Grant Edwards wrote: >On 2005-09-12, Jacek Pop?awski <[EMAIL PROTECTED]> wrote: > >>> ready = select.select(tocheck, [], [], 0.25) ##continues after 0.25s >>> for file in ready[0]: >>> try: >>>

Re: read stdout/stderr without blocking

2005-09-13 Thread Grant Edwards
On 2005-09-13, Jacek Pop?awski <[EMAIL PROTECTED]> wrote: > Grant Edwards wrote: >> 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. > > I created another thr

Re: read stdout/stderr without blocking

2005-09-13 Thread Jacek Popławski
Grant Edwards wrote: > 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. I created another thread with single read(), it works, as long as I have only one PI

Re: read stdout/stderr without blocking

2005-09-13 Thread Grant Edwards
On 2005-09-13, Jacek Pop³awski <[EMAIL PROTECTED]> 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 ch

Re: read stdout/stderr without blocking

2005-09-13 Thread Peter Hansen
Jacek Popławski wrote: > Grant Edwards wrote: > >> On 2005-09-12, Jacek Pop?awski <[EMAIL PROTECTED]> wrote: >> ready = select.select(tocheck, [], [], 0.25) ##continues after 0.25s for file in ready[0]: try: text = os.read(file, 102

Re: read stdout/stderr without blocking

2005-09-13 Thread Jacek Popławski
Only solution which works for now is to redirect stderr to stdout, and read stdout on thread. Code without thread or with read() or read(n) (when n>1) can block. Code with select() and read(1) works, but it is very slow. -- http://mail.python.org/mailman/listinfo/python-list

Re: read stdout/stderr without blocking

2005-09-13 Thread Jacek Popławski
Grant Edwards wrote: > On 2005-09-12, Jacek Pop?awski <[EMAIL PROTECTED]> 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

Re: read stdout/stderr without blocking

2005-09-12 Thread Grant Edwards
On 2005-09-12, Jacek Pop?awski <[EMAIL PROTECTED]> 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

Re: read stdout/stderr without blocking

2005-09-12 Thread Adriaan Renting
The line only means it will read a maximum of 1024 characters, most of the output I try to catch is much shorter. I think that if the output is longer as 1024, it will read the rest after another call to select.select, but I think I have not yet come across that case and have not tested it. I s

Re: read stdout/stderr without blocking

2005-09-12 Thread Jacek Popławski
> 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? -- http://mail.python

Re: read stdout/stderr without blocking

2005-09-12 Thread Adriaan Renting
I was not aware you were using Windows, you might need to find something similar to select and pty that works in Windows or maybe go though Cygwin, I don't know. I'm on Linux, the only help I can offer is showing you my working code, that's a mix of Pexpect, subProcess and Parseltongue. I'm not

Re: read stdout/stderr without blocking

2005-09-12 Thread Jacek Popławski
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? -- http://mail.python.org/mailman/listi

Re: read stdout/stderr without blocking

2005-09-12 Thread Adriaan Renting
Check out the select module, for an example on how to use it: pexpect.sourceforge.net >>>Jacek Pop*awski <[EMAIL PROTECTED]> 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 stdout/stderr without blocking

2005-09-12 Thread Jacek Popławski
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 comman