Issue 7240: subprocess.Popen.stdout.flush fails os OS-X 10.6.1 (original) (raw)

Created on 2009-10-30 05:15 by petegibson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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, ...
History
Date User Action Args
2022-04-11 14:56:54 admin set github: 51489
2009-11-03 20:57:24 pjenvey set status: open -> closedresolution: not a bug
2009-11-03 07:52:39 ronaldoussoren set messages: +
2009-10-30 13:42:27 petegibson set messages: +
2009-10-30 06:26:13 ned.deily set nosy: + ned.deily, ronaldoussorenmessages: + assignee: ronaldoussorencomponents: + macOS
2009-10-30 06:23:15 pjenvey set nosy: + pjenveymessages: +
2009-10-30 05:15:47 petegibson create