Dialog with a process via subprocess.Popen blocks forever
Hendrik van Rooyen
mail at microcorp.co.za
Thu Mar 1 00:54:24 EST 2007
<bayer.justin at googlemail.com> wrote:
> Is it possible to read to and write to the std streams of a
> subprocess? What am I doing wrong?
I think this problem lies deeper - there has been a lot of
complaints about blocking and data getting stuck in pipes
and sockets...
I have noticed that the Python file objects seem to be
inherently half duplex, but I am not sure if it is python
or the underlying OS. (Suse 10 in my case)
You can fix it by unblocking using the fcntl module,
but then all your accesses have to be in try - except
clauses.
It may be worth making some sort of FAQ on this
subject, as it appears from time to time.
The standard advice has been to use file.flush()
after file.write(), but if you are threading and
have called file.read(n), then the flushing does
not help - this is why I say that the file object
seems to be inherently half duplex.
It makes perfect sense, of course, if the file is a
real disk file, as you have to finish the read before
you can move the heads to do the write- but for
pipes, sockets and RS-232 serial lines it does not
make so much sense.
Does anybody know where it comes from -
Python, the various OSses, or C?
- Hendrik
More information about the Python-list
mailing list