This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author izbyshev
Recipients gregory.p.smith, izbyshev, pitrou, vstinner
Date 2017-12-10.17:14:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1512926046.73.0.213398074469.issue32270@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-12-10 17:14:06izbyshevsetrecipients: + izbyshev, gregory.p.smith, pitrou, vstinner
2017-12-10 17:14:06izbyshevsetmessageid: <1512926046.73.0.213398074469.issue32270@psf.upfronthosting.co.za>
2017-12-10 17:14:06izbyshevlinkissue32270 messages
2017-12-10 17:14:06izbyshevcreate