Bugs item #1574310, was opened at 2006-10-10 09:45
Message generated for change (Comment added) made by ronaldoussoren
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1574310&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: dtrosset (dtrosset)
Assigned to: Nobody/Anonymous (nobody)
Summary: os.popen with os.close gives error message

Initial Comment:
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.


----------------------------------------------------------------------

>Comment By: Ronald Oussoren (ronaldoussoren)
Date: 2006-11-08 08:03

Message:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1574310&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to