test_wait4.py 1.1 KB

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