| 49 | support.wait_process(cpid, exitcode=exitcode) |
| 50 | |
| 51 | def test_wait(self): |
| 52 | for i in range(NUM_THREADS): |
| 53 | thread = threading.Thread(target=self.f, args=(i,)) |
| 54 | thread.start() |
| 55 | self.threads.append(thread) |
| 56 | |
| 57 | # busy-loop to wait for threads |
| 58 | for _ in support.sleeping_retry(support.SHORT_TIMEOUT): |
| 59 | if len(self.alive) >= NUM_THREADS: |
| 60 | break |
| 61 | |
| 62 | a = sorted(self.alive.keys()) |
| 63 | self.assertEqual(a, list(range(NUM_THREADS))) |
| 64 | |
| 65 | prefork_lives = self.alive.copy() |
| 66 | |
| 67 | # Ignore the warning about fork with threads. |
| 68 | with warnings.catch_warnings(category=DeprecationWarning, |
| 69 | action="ignore"): |
| 70 | if (cpid := os.fork()) == 0: |
| 71 | # Child |
| 72 | time.sleep(LONGSLEEP) |
| 73 | n = 0 |
| 74 | for key in self.alive: |
| 75 | if self.alive[key] != prefork_lives[key]: |
| 76 | n += 1 |
| 77 | os._exit(n) |
| 78 | else: |
| 79 | # Parent |
| 80 | self.wait_impl(cpid, exitcode=0) |