MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_forkinthread

Method test_forkinthread

Lib/test/test_thread.py:229–254  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

227 @unittest.skipUnless(hasattr(os, 'fork'), 'need os.fork')
228 @threading_helper.reap_threads
229 def test_forkinthread(self):
230 pid = None
231
232 def fork_thread(read_fd, write_fd):
233 nonlocal pid
234
235 # fork in a thread
236 pid = os.fork()
237 if pid:
238 # parent process
239 return
240
241 # child process
242 try:
243 os.close(read_fd)
244 os.write(write_fd, b"OK")
245 finally:
246 os._exit(0)
247
248 with threading_helper.wait_threads_exit():
249 thread.start_new_thread(fork_thread, (self.read_fd, self.write_fd))
250 self.assertEqual(os.read(self.read_fd, 2), b"OK")
251 os.close(self.write_fd)
252
253 self.assertIsNotNone(pid)
254 support.wait_process(pid, exitcode=0)
255
256 def tearDown(self):
257 try:

Callers

nothing calls this directly

Calls 4

assertIsNotNoneMethod · 0.80
assertEqualMethod · 0.45
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected