test_wait4.py 1.2 KB

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