test_wait3.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """This test checks for correct wait3() behavior.
  2. """
  3. import os
  4. import time
  5. import unittest
  6. from test.fork_wait import ForkWait
  7. from test.test_support import run_unittest, reap_children
  8. try:
  9. os.fork
  10. except AttributeError:
  11. raise unittest.SkipTest, "os.fork not defined -- skipping test_wait3"
  12. try:
  13. os.wait3
  14. except AttributeError:
  15. raise unittest.SkipTest, "os.wait3 not defined -- skipping test_wait3"
  16. class Wait3Test(ForkWait):
  17. def wait_impl(self, cpid):
  18. for i in range(10):
  19. # wait3() 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.wait3(os.WNOHANG)
  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(Wait3Test)
  30. reap_children()
  31. if __name__ == "__main__":
  32. test_main()