(self, code, exitcode, callback=None)
| 3523 | self.assertEqual(int(stdout), os.getpid()) |
| 3524 | |
| 3525 | def check_waitpid(self, code, exitcode, callback=None): |
| 3526 | if sys.platform == 'win32': |
| 3527 | # On Windows, os.spawnv() simply joins arguments with spaces: |
| 3528 | # arguments need to be quoted |
| 3529 | args = [f'"{sys.executable}"', '-c', f'"{code}"'] |
| 3530 | else: |
| 3531 | args = [sys.executable, '-c', code] |
| 3532 | pid = os.spawnv(os.P_NOWAIT, sys.executable, args) |
| 3533 | |
| 3534 | if callback is not None: |
| 3535 | callback(pid) |
| 3536 | |
| 3537 | # don't use support.wait_process() to test directly os.waitpid() |
| 3538 | # and os.waitstatus_to_exitcode() |
| 3539 | pid2, status = os.waitpid(pid, 0) |
| 3540 | self.assertEqual(os.waitstatus_to_exitcode(status), exitcode) |
| 3541 | self.assertEqual(pid2, pid) |
| 3542 | |
| 3543 | def test_waitpid(self): |
| 3544 | self.check_waitpid(code='pass', exitcode=0) |
no test coverage detected