bpo-40094: Add test.support.wait_process() (GH-19254)
Moreover, the following tests now check the child process exit code:
* test_os.PtyTests
* test_mailbox.test_lock_conflict()
* test_tempfile.test_process_awareness()
* test_uuid.testIssue8621()
* multiprocessing resource tracker tests
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index e223522..2ad3c5c 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -727,30 +727,19 @@
locks_held__ready_to_fork.wait()
pid = os.fork()
- if pid == 0: # Child.
+ if pid == 0:
+ # Child process
try:
test_logger.info(r'Child process did not deadlock. \o/')
finally:
os._exit(0)
- else: # Parent.
+ else:
+ # Parent process
test_logger.info(r'Parent process returned from fork. \o/')
fork_happened__release_locks_and_end_thread.set()
lock_holder_thread.join()
- start_time = time.monotonic()
- while True:
- test_logger.debug('Waiting for child process.')
- waited_pid, status = os.waitpid(pid, os.WNOHANG)
- if waited_pid == pid:
- break # child process exited.
- if time.monotonic() - start_time > 7:
- break # so long? implies child deadlock.
- time.sleep(0.05)
- test_logger.debug('Done waiting.')
- if waited_pid != pid:
- os.kill(pid, signal.SIGKILL)
- waited_pid, status = os.waitpid(pid, 0)
- self.fail("child process deadlocked.")
- self.assertEqual(status, 0, msg="child process error")
+
+ support.wait_process(pid, exitcode=0)
class BadStream(object):