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

Method test_setsid

Lib/test/test_os/test_posix.py:2052–2081  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2050 signal.NSIG+1])
2051
2052 def test_setsid(self):
2053 rfd, wfd = os.pipe()
2054 self.addCleanup(os.close, rfd)
2055 try:
2056 os.set_inheritable(wfd, True)
2057
2058 code = textwrap.dedent(f"""
2059 import os
2060 fd = {wfd}
2061 sid = os.getsid(0)
2062 os.write(fd, str(sid).encode())
2063 """)
2064
2065 try:
2066 pid = self.spawn_func(sys.executable,
2067 [sys.executable, "-c", code],
2068 os.environ, setsid=True)
2069 except NotImplementedError as exc:
2070 self.skipTest(f"setsid is not supported: {exc!r}")
2071 except PermissionError as exc:
2072 self.skipTest(f"setsid failed with: {exc!r}")
2073 finally:
2074 os.close(wfd)
2075
2076 support.wait_process(pid, exitcode=0)
2077
2078 output = os.read(rfd, 100)
2079 child_sid = int(output)
2080 parent_sid = os.getsid(os.getpid())
2081 self.assertNotEqual(parent_sid, child_sid)
2082
2083 @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'),
2084 'need signal.pthread_sigmask()')

Callers

nothing calls this directly

Calls 8

addCleanupMethod · 0.80
set_inheritableMethod · 0.80
skipTestMethod · 0.80
assertNotEqualMethod · 0.80
pipeMethod · 0.45
dedentMethod · 0.45
closeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected