1 | n/a | """This test checks for correct wait4() behavior. |
---|
2 | n/a | """ |
---|
3 | n/a | |
---|
4 | n/a | import os |
---|
5 | n/a | import time |
---|
6 | n/a | import sys |
---|
7 | n/a | import unittest |
---|
8 | n/a | from test.fork_wait import ForkWait |
---|
9 | n/a | from test.support import reap_children, get_attribute |
---|
10 | n/a | |
---|
11 | n/a | # If either of these do not exist, skip this test. |
---|
12 | n/a | get_attribute(os, 'fork') |
---|
13 | n/a | get_attribute(os, 'wait4') |
---|
14 | n/a | |
---|
15 | n/a | |
---|
16 | n/a | class Wait4Test(ForkWait): |
---|
17 | n/a | def wait_impl(self, cpid): |
---|
18 | n/a | option = os.WNOHANG |
---|
19 | n/a | if sys.platform.startswith('aix'): |
---|
20 | n/a | # Issue #11185: wait4 is broken on AIX and will always return 0 |
---|
21 | n/a | # with WNOHANG. |
---|
22 | n/a | option = 0 |
---|
23 | n/a | deadline = time.monotonic() + 10.0 |
---|
24 | n/a | while time.monotonic() <= deadline: |
---|
25 | n/a | # wait4() shouldn't hang, but some of the buildbots seem to hang |
---|
26 | n/a | # in the forking tests. This is an attempt to fix the problem. |
---|
27 | n/a | spid, status, rusage = os.wait4(cpid, option) |
---|
28 | n/a | if spid == cpid: |
---|
29 | n/a | break |
---|
30 | n/a | time.sleep(0.1) |
---|
31 | n/a | self.assertEqual(spid, cpid) |
---|
32 | n/a | self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) |
---|
33 | n/a | self.assertTrue(rusage) |
---|
34 | n/a | |
---|
35 | n/a | def tearDownModule(): |
---|
36 | n/a | reap_children() |
---|
37 | n/a | |
---|
38 | n/a | if __name__ == "__main__": |
---|
39 | n/a | unittest.main() |
---|