1"""This test checks for correct wait4() behavior. 2""" 3 4import os 5import time 6import sys 7import unittest 8from test.fork_wait import ForkWait 9from test import support 10 11# If either of these do not exist, skip this test. 12support.get_attribute(os, 'fork') 13support.get_attribute(os, 'wait4') 14 15 16class Wait4Test(ForkWait): 17 def wait_impl(self, cpid, *, exitcode): 18 option = os.WNOHANG 19 if sys.platform.startswith('aix'): 20 # Issue #11185: wait4 is broken on AIX and will always return 0 21 # with WNOHANG. 22 option = 0 23 deadline = time.monotonic() + support.SHORT_TIMEOUT 24 while time.monotonic() <= deadline: 25 # wait4() shouldn't hang, but some of the buildbots seem to hang 26 # in the forking tests. This is an attempt to fix the problem. 27 spid, status, rusage = os.wait4(cpid, option) 28 if spid == cpid: 29 break 30 time.sleep(0.1) 31 self.assertEqual(spid, cpid) 32 self.assertEqual(os.waitstatus_to_exitcode(status), exitcode) 33 self.assertTrue(rusage) 34 35def tearDownModule(): 36 support.reap_children() 37 38if __name__ == "__main__": 39 unittest.main() 40