move sections
[python/dscho.git] / Lib / test / test_wait3.py
blob150783b6555e3b3b768fc16b99ba6c267cd28839
1 """This test checks for correct wait3() behavior.
2 """
4 import os
5 import time
6 import unittest
7 from test.fork_wait import ForkWait
8 from test.test_support import run_unittest, reap_children
10 try:
11 os.fork
12 except AttributeError:
13 raise unittest.SkipTest, "os.fork not defined -- skipping test_wait3"
15 try:
16 os.wait3
17 except AttributeError:
18 raise unittest.SkipTest, "os.wait3 not defined -- skipping test_wait3"
20 class Wait3Test(ForkWait):
21 def wait_impl(self, cpid):
22 for i in range(10):
23 # wait3() 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.wait3(os.WNOHANG)
26 if spid == cpid:
27 break
28 time.sleep(1.0)
30 self.assertEqual(spid, cpid)
31 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
32 self.assertTrue(rusage)
34 def test_main():
35 run_unittest(Wait3Test)
36 reap_children()
38 if __name__ == "__main__":
39 test_main()