Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subprocess.Popen.stdout.flush fails os OS-X 10.6.1 #51489

Closed
petegibson mannequin opened this issue Oct 30, 2009 · 5 comments
Closed

subprocess.Popen.stdout.flush fails os OS-X 10.6.1 #51489

petegibson mannequin opened this issue Oct 30, 2009 · 5 comments
Assignees
Labels
OS-mac stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@petegibson
Copy link
Mannequin

petegibson mannequin commented Oct 30, 2009

BPO 7240
Nosy @ronaldoussoren, @pjenvey, @ned-deily

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/ronaldoussoren'
closed_at = <Date 2009-11-03.20:57:24.046>
created_at = <Date 2009-10-30.05:15:47.705>
labels = ['OS-mac', 'invalid', 'library', 'type-crash']
title = 'subprocess.Popen.stdout.flush fails os OS-X 10.6.1'
updated_at = <Date 2009-11-03.20:57:24.045>
user = 'https://bugs.python.org/petegibson'

bugs.python.org fields:

activity = <Date 2009-11-03.20:57:24.045>
actor = 'pjenvey'
assignee = 'ronaldoussoren'
closed = True
closed_date = <Date 2009-11-03.20:57:24.046>
closer = 'pjenvey'
components = ['Library (Lib)', 'macOS']
creation = <Date 2009-10-30.05:15:47.705>
creator = 'petegibson'
dependencies = []
files = []
hgrepos = []
issue_num = 7240
keywords = []
message_count = 5.0
messages = ['94694', '94695', '94696', '94705', '94858']
nosy_count = 4.0
nosy_names = ['ronaldoussoren', 'pjenvey', 'ned.deily', 'petegibson']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'crash'
url = 'https://bugs.python.org/issue7240'
versions = ['Python 2.6']

@petegibson
Copy link
Mannequin Author

petegibson mannequin commented Oct 30, 2009

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 "<stdin>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor

However it works on Python 2.6.2 on Linux.

@petegibson petegibson mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 30, 2009
@pjenvey
Copy link
Member

pjenvey commented Oct 30, 2009

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

@ned-deily
Copy link
Member

Philip is correct:

>>> p.stdout.flush()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor
>>> p.stdout
<open file '<fdopen>', 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 "<stdin>", 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.

@petegibson
Copy link
Mannequin Author

petegibson mannequin commented Oct 30, 2009

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?

@ronaldoussoren
Copy link
Contributor

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, ...

@pjenvey pjenvey closed this as completed Nov 3, 2009
@pjenvey pjenvey added the invalid label Nov 3, 2009
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-mac stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

3 participants