#1153769: document PEP 237 changes to string formatting.
[python.git] / Lib / test / test_wait4.py
blob9f7fc14a64af3cb95315874ea58d2499dde3b23a
1 """This test checks for correct wait4() behavior.
2 """
4 import os
5 import time
6 from test.fork_wait import ForkWait
7 from test.test_support import TestSkipped, run_unittest, reap_children
9 try:
10 os.fork
11 except AttributeError:
12 raise TestSkipped, "os.fork not defined -- skipping test_wait4"
14 try:
15 os.wait4
16 except AttributeError:
17 raise TestSkipped, "os.wait4 not defined -- skipping test_wait4"
19 class Wait4Test(ForkWait):
20 def wait_impl(self, cpid):
21 for i in range(10):
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, os.WNOHANG)
25 if spid == cpid:
26 break
27 time.sleep(1.0)
28 self.assertEqual(spid, cpid)
29 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
30 self.assertTrue(rusage)
32 def test_main():
33 run_unittest(Wait4Test)
34 reap_children()
36 if __name__ == "__main__":
37 test_main()