ยปCore Development>Code coverage>Lib/test/test_wait3.py

Python code coverage for Lib/test/test_wait3.py

#countcontent
1n/a"""This test checks for correct wait3() behavior.
2n/a"""
3n/a
4n/aimport os
5n/aimport time
6n/aimport unittest
7n/afrom test.fork_wait import ForkWait
8n/afrom test.support import reap_children
9n/a
10n/aif not hasattr(os, 'fork'):
11n/a raise unittest.SkipTest("os.fork not defined")
12n/a
13n/aif not hasattr(os, 'wait3'):
14n/a raise unittest.SkipTest("os.wait3 not defined")
15n/a
16n/aclass Wait3Test(ForkWait):
17n/a def wait_impl(self, cpid):
18n/a # This many iterations can be required, since some previously run
19n/a # tests (e.g. test_ctypes) could have spawned a lot of children
20n/a # very quickly.
21n/a deadline = time.monotonic() + 10.0
22n/a while time.monotonic() <= deadline:
23n/a # wait3() shouldn't hang, but some of the buildbots seem to hang
24n/a # in the forking tests. This is an attempt to fix the problem.
25n/a spid, status, rusage = os.wait3(os.WNOHANG)
26n/a if spid == cpid:
27n/a break
28n/a time.sleep(0.1)
29n/a
30n/a self.assertEqual(spid, cpid)
31n/a self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
32n/a self.assertTrue(rusage)
33n/a
34n/adef tearDownModule():
35n/a reap_children()
36n/a
37n/aif __name__ == "__main__":
38n/a unittest.main()