| 422 | pid = None |
| 423 | |
| 424 | def fork_thread(read_fd, write_fd): |
| 425 | nonlocal pid |
| 426 | |
| 427 | # Ignore the warning about fork with threads. |
| 428 | with warnings.catch_warnings(category=DeprecationWarning, |
| 429 | action="ignore"): |
| 430 | # fork in a thread (DANGER, undefined per POSIX) |
| 431 | if (pid := os.fork()): |
| 432 | # parent process |
| 433 | return |
| 434 | |
| 435 | # child process |
| 436 | try: |
| 437 | os.close(read_fd) |
| 438 | os.write(write_fd, b"OK") |
| 439 | finally: |
| 440 | os._exit(0) |
| 441 | |
| 442 | with threading_helper.wait_threads_exit(): |
| 443 | thread.start_new_thread(fork_thread, (self.read_fd, self.write_fd)) |