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

Method test_process_awareness

Lib/test/test_tempfile.py:195–220  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

193
194 @support.requires_fork()
195 def test_process_awareness(self):
196 # ensure that the random source differs between
197 # child and parent.
198 read_fd, write_fd = os.pipe()
199 pid = None
200 try:
201 pid = os.fork()
202 if not pid:
203 # child process
204 os.close(read_fd)
205 os.write(write_fd, next(self.r).encode("ascii"))
206 os.close(write_fd)
207 # bypass the normal exit handlers- leave those to
208 # the parent.
209 os._exit(0)
210
211 # parent process
212 parent_value = next(self.r)
213 child_value = os.read(read_fd, len(parent_value)).decode("ascii")
214 finally:
215 if pid:
216 support.wait_process(pid, exitcode=0)
217
218 os.close(read_fd)
219 os.close(write_fd)
220 self.assertNotEqual(child_value, parent_value)
221
222
223

Callers

nothing calls this directly

Calls 8

assertNotEqualMethod · 0.80
pipeMethod · 0.45
closeMethod · 0.45
writeMethod · 0.45
encodeMethod · 0.45
_exitMethod · 0.45
decodeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected