New submission from Alexey Izbyshev <izbys...@ispras.ru>: Demonstration:
$ cat test.py import os import subprocess import sys fd = os.dup(sys.stdout.fileno()) subprocess.call([sys.executable, '-c', 'import sys;' 'print("Hello stdout");' 'print("Hello fd", file=open(int(sys.argv[1]), "w"))', str(fd)], stdout=fd, pass_fds=[fd]) $ python3 test.py Hello stdout Traceback (most recent call last): File "<string>", line 1, in <module> OSError: [Errno 9] Bad file descriptor I see two issues here: 1. The fact that file descriptors specified for redirection are closed (even with close_fds=False) unless in range [0, 2] is not documented and not tested. If I change the corresponding code in _posixsubprocess.c to close them only if they are ends of pipes created by subprocess itself, all tests still pass. Also, shells behave differently: e.g., in command 'echo 3>&1' fd 3 is duplicated but not closed in the child, so subprocess behavior may be not what people expect. 2. pass_fds interaction with (1) should be fixed and documented. We may either raise ValueError if pass_fds contains a redirected fd or don't close such a redirected fd. Please provide your thoughts. ---------- components: Library (Lib) files: test.py messages: 307962 nosy: gregory.p.smith, izbyshev, pitrou, vstinner priority: normal severity: normal status: open title: subprocess closes redirected fds even if they are in pass_fds type: behavior versions: Python 3.6, Python 3.7 Added file: https://bugs.python.org/file47329/test.py _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32270> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com