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