(self)
| 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: |
nothing calls this directly
no test coverage detected