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

os.popen with os.close gives error message #44108

Closed
dtrosset mannequin opened this issue Oct 10, 2006 · 3 comments
Closed

os.popen with os.close gives error message #44108

dtrosset mannequin opened this issue Oct 10, 2006 · 3 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@dtrosset
Copy link
Mannequin

dtrosset mannequin commented Oct 10, 2006

BPO 1574310
Nosy @ronaldoussoren, @devdanzin

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 = None
closed_at = <Date 2009-05-12.17:05:12.405>
created_at = <Date 2006-10-10.07:45:08.000>
labels = ['invalid', 'type-bug', 'library']
title = 'os.popen with os.close gives error message'
updated_at = <Date 2009-05-12.17:05:12.404>
user = 'https://bugs.python.org/dtrosset'

bugs.python.org fields:

activity = <Date 2009-05-12.17:05:12.404>
actor = 'ajaksu2'
assignee = 'none'
closed = True
closed_date = <Date 2009-05-12.17:05:12.405>
closer = 'ajaksu2'
components = ['Library (Lib)']
creation = <Date 2006-10-10.07:45:08.000>
creator = 'dtrosset'
dependencies = []
files = []
hgrepos = []
issue_num = 1574310
keywords = []
message_count = 3.0
messages = ['61018', '61019', '84528']
nosy_count = 3.0
nosy_names = ['ronaldoussoren', 'ajaksu2', 'dtrosset']
pr_nums = []
priority = 'low'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1574310'
versions = ['Python 2.6']

@dtrosset
Copy link
Mannequin Author

dtrosset mannequin commented Oct 10, 2006

Given the following code:

  import os
  child_stdin = os.popen("cat -", "w")
  old_stdout = os.dup(1)
  os.close(child_stdin.fileno())
  print "foo"
  os.dup2(old_stdout, 1)
  os.close(old_stdout)

I got these different results depending on the version
of python I am using.

$ python2.4 -V 
Python 2.4.4c0
$ python2.4 test.py 
foo
close failed: [Errno 9] Bad file descriptor

$ python2.3 -V 
Python 2.3.5
$ python2.3 test/new/test.py 
foo

My .02$ guess is that underlying file descriptor of
child_stdin being closed, when trying to delete this
object, it tries again to close it.

@dtrosset dtrosset mannequin added stdlib Python modules in the Lib dir labels Oct 10, 2006
@ronaldoussoren
Copy link
Contributor

Logged In: YES
user_id=580910

IMHO this is "don't do that then" territory. You're poking around in the inside of file objects, you have to be careful if you do that.

BTW. What are you trying to accomplish? If you set sys.stdout to child_stdin (e.g. "import sys; sys.stdout = child_stdin"), print will write to the
pipe. If you really want to be sure that the C-level variable stdout writes to the pipe: os.dup2(child_stdout.fileno(), 1). You can then close
child_stdout, but still have to do the 'os.dup(1)' part if you want to restore the real stdout later on.

@devdanzin
Copy link
Mannequin

devdanzin mannequin commented Mar 30, 2009

I'll close this based on Ronald's analysis unless opposition is voiced.

@devdanzin devdanzin mannequin added type-bug An unexpected behavior, bug, or error labels Mar 30, 2009
@devdanzin devdanzin mannequin closed this as completed May 12, 2009
@devdanzin devdanzin mannequin added the invalid label May 12, 2009
@devdanzin devdanzin mannequin closed this as completed May 12, 2009
@devdanzin devdanzin mannequin added the invalid label May 12, 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
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant