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