[issue16140] subprocess.Popen the os.close calls in _execute_child can raise an EBADF exception

Gregory P. Smith report at bugs.python.org
Fri Oct 5 09:17:19 CEST 2012


Gregory P. Smith added the comment:

What you've described makes sense.

The file descriptors are indeed conditionally wrapped in file objects using io.open which could lead to a double close in the error case in a threaded application.  yuck.

1) The code needs to check if the fd was wrapped before calling os.close() on it. It could do this by checking the sys.stdin, sys.stdout and sys.stderr attributes respectively for each fd.

2) another option that is a little more clear code wise as it doesn't try to use an implied connection between the stdin/stdout/strerr attributes would be to _always_ wrap the fd's that this can happen to in an io object (regardless of if they've been assigned to the stdin/stdout/stderr attributes) and pass those to _execute_child.  Their .fileno() method can be used for the value to pass to _posixsubprocess.fork_exec().  And the os.close on those would turn into a close method call which won't allow double close EBADF errors.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16140>
_______________________________________


More information about the Python-bugs-list mailing list