MCPcopy Index your code
hub / github.com/python/cpython / test_pass_fds_inheritable

Method test_pass_fds_inheritable

Lib/test/test_subprocess.py:3180–3204  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3178 self.assertIn('overriding close_fds', str(context.warning))
3179
3180 def test_pass_fds_inheritable(self):
3181 script = support.findfile("fd_status.py", subdir="subprocessdata")
3182
3183 inheritable, non_inheritable = os.pipe()
3184 self.addCleanup(os.close, inheritable)
3185 self.addCleanup(os.close, non_inheritable)
3186 os.set_inheritable(inheritable, True)
3187 os.set_inheritable(non_inheritable, False)
3188 pass_fds = (inheritable, non_inheritable)
3189 args = [sys.executable, script]
3190 args += list(map(str, pass_fds))
3191
3192 p = subprocess.Popen(args,
3193 stdout=subprocess.PIPE, close_fds=True,
3194 pass_fds=pass_fds)
3195 output, ignored = p.communicate()
3196 fds = set(map(int, output.split(b',')))
3197
3198 # the inheritable file descriptor must be inherited, so its inheritable
3199 # flag must be set in the child process after fork() and before exec()
3200 self.assertEqual(fds, set(pass_fds), "output=%a" % output)
3201
3202 # inheritable flag must not be changed in the parent process
3203 self.assertEqual(os.get_inheritable(inheritable), True)
3204 self.assertEqual(os.get_inheritable(non_inheritable), False)
3205
3206
3207 # bpo-32270: Ensure that descriptors specified in pass_fds

Callers

nothing calls this directly

Calls 9

communicateMethod · 0.95
listClass · 0.85
setFunction · 0.85
addCleanupMethod · 0.80
set_inheritableMethod · 0.80
pipeMethod · 0.45
splitMethod · 0.45
assertEqualMethod · 0.45
get_inheritableMethod · 0.45

Tested by

no test coverage detected