msg94694 - (view) |
Author: Peter Gibson (petegibson) |
Date: 2009-10-30 05:15 |
subprocess.Popen.stdout.flush() fails on OS-X 10.6.1 under the bundled Python 2.6.1 and 2.6.3 from Macports. >>> from subprocess import Popen, PIPE >>> p = Popen('cat', stdin=PIPE, stdout=PIPE) >>> p.stdout.flush() Traceback (most recent call last): File "", line 1, in IOError: [Errno 9] Bad file descriptor However it works on Python 2.6.2 on Linux. |
|
|
msg94695 - (view) |
Author: Philip Jenvey (pjenvey) *  |
Date: 2009-10-30 06:23 |
Why are you flushing stdout? It's read-only and flush is for writing. This behavior is dependent on the underlying platform's fflush, which really *should* be raising EBADF when fflushing a read only file, anyway |
|
|
msg94696 - (view) |
Author: Ned Deily (ned.deily) *  |
Date: 2009-10-30 06:26 |
Philip is correct: >>> p.stdout.flush() Traceback (most recent call last): File "", line 1, in IOError: [Errno 9] Bad file descriptor >>> p.stdout <open file '', mode 'rb' at 0x100527470> You'll get the same error on OS X (at least as far back as Python 2.3.5 on OS X 10.4) if you try to flush a disk read-only file: >>> f = open('a.txt', 'rb') >>> f.flush() Traceback (most recent call last): File "", line 1, in ? IOError: [Errno 9] Bad file descriptor Note, both the OS X and Linux 2.6 fflush(3) man pages clearly state that EBADF can be returned if the stream is not open for writing but there seems to be a difference in behavior between the two OS's. As this doesn't seem to be a new issue and can easily be avoided (don't flush a read-only file), I suggest closing the issue. |
|
|
msg94705 - (view) |
Author: Peter Gibson (petegibson) |
Date: 2009-10-30 13:42 |
Not my code, but as it's using a pipe to communicate with another process, I assume that the flush call is intended to discard any unwanted output prior to sending a command and processing the result. Is there another way to achieve the same effect, such as reading and remaining characters in the buffer? |
|
|
msg94858 - (view) |
Author: Ronald Oussoren (ronaldoussoren) *  |
Date: 2009-11-03 07:52 |
I don't think so. stdio on OSX has a fdiscard function, but that's not exposed to Python. I tend to explicitly synchronize on prompts when communicating with an interactive program over a pipe. That is, read until you found the prompt, then send a command, then read again until getting to the prompt, ... |
|
|