Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-26 Thread Martin v. Loewis
> Can this really be made safe without an explicit flow control protocol, > such as a pseudo-TTY? stdio reads data from pipes such as stdin in 4K > or so chunks. I don't think the subprocess module uses stdio. > I can easily imagine the child blocking while it waits > for its stdin buffer to fil

Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-26 Thread Nick Coghlan
Andrew Bennetts wrote: > Daniel Stutzbach wrote: > [...] >> If you really need to communicate with multiple subprocesses (which so far >> has >> not been suggested as a motivating example), then you can use select(). > > Not portably. select() on windows only works on sockets. In addition, sele

Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-26 Thread Andrew Bennetts
Daniel Stutzbach wrote: [...] > > If you really need to communicate with multiple subprocesses (which so far has > not been suggested as a motivating example), then you can use select(). Not portably. select() on windows only works on sockets. -Andrew. _

Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-26 Thread Daniel Stutzbach
On Mon, Jan 26, 2009 at 4:43 PM, Nick Coghlan wrote: > With the vanilla subprocess Popen implmentation, the stdin.write calls > can actually both block if the stdin buffer is full (waiting for the > child process to clear space) and the stdout.readline call can > definitely block (waiting for the

Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-26 Thread Nick Coghlan
Daniel Stutzbach wrote: > I'm confused. What's wrong with the following? > > p = Popen('do_something', stdin=PIPE, stdout=PIPE) > p.stdin.write('la la la\n') > p.stdin.flush() > line = p.stdout.readline() > p.stdin.write(process(line)) > p.stdin.flush() > > If you want t

Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-26 Thread Guido van Rossum
On Mon, Jan 26, 2009 at 12:44 AM, anatoly techtonik wrote: > You can't launch a process and communicate with it without blocking at > some point. The scenario where you can periodically check output and > error pipes without blocking and send input is not supported. > > Scenario One: control conso

Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-26 Thread Daniel Stutzbach
I'm confused. What's wrong with the following? p = Popen('do_something', stdin=PIPE, stdout=PIPE) p.stdin.write('la la la\n') p.stdin.flush() line = p.stdout.readline() p.stdin.write(process(line)) p.stdin.flush() If you want to see if data is available on p.stdout, use t

Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-26 Thread Hrvoje Niksic
Nick Craig-Wood wrote: But for the conversational case (eg using it to do a remote login) it doesn't work at all :- run child send stuff to stdin child reads stdin and writes stdout Can this really be made safe without an explicit flow control protocol, such as a pseudo-TTY? stdio read

Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-26 Thread Nick Craig-Wood
On Sat, Jan 24, 2009 at 07:58:40AM -0800, Guido van Rossum wrote: > I'm confused. The subprocess already allows reading/writing its > stdin/stdout/stderr, and AFAIK it's a platform-neutral API. I'm sure > there's something missing, but your post doesn't make it clear what > exactly, and the recipe

Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-26 Thread anatoly techtonik
Hi, Guido You can't launch a process and communicate with it without blocking at some point. The scenario where you can periodically check output and error pipes without blocking and send input is not supported. Scenario One: control console program. This implies reading from input and writing re

Re: [Python-Dev] subprocess crossplatformness and async communication

2009-01-24 Thread Guido van Rossum
Anatoly, I'm confused. The subprocess already allows reading/writing its stdin/stdout/stderr, and AFAIK it's a platform-neutral API. I'm sure there's something missing, but your post doesn't make it clear what exactly, and the recipe you reference is too large to digest easily. Can you explain wha

[Python-Dev] subprocess crossplatformness and async communication

2009-01-24 Thread anatoly techtonik
Greetings, This turned out to be a rather long post that in short can be summarized as: "please-please-please, include asynchronous process communication in subprocess module and do not allow "available only on ..." functionality", because it hurts the brain". Code to speak for itself: http://cod