test_wait3.py 1.03 KB
Newer Older
1 2 3 4
"""This test checks for correct wait3() behavior.
"""

import os
5
import time
Benjamin Peterson's avatar
Benjamin Peterson committed
6
import unittest
7
from test.fork_wait import ForkWait
Benjamin Peterson's avatar
Benjamin Peterson committed
8
from test.support import run_unittest, reap_children
9 10 11 12

try:
    os.fork
except AttributeError:
Benjamin Peterson's avatar
Benjamin Peterson committed
13
    raise unittest.SkipTest("os.fork not defined -- skipping test_wait3")
14 15 16 17

try:
    os.wait3
except AttributeError:
Benjamin Peterson's avatar
Benjamin Peterson committed
18
    raise unittest.SkipTest("os.wait3 not defined -- skipping test_wait3")
19 20 21

class Wait3Test(ForkWait):
    def wait_impl(self, cpid):
22 23 24 25
        for i in range(10):
            # wait3() shouldn't hang, but some of the buildbots seem to hang
            # in the forking tests.  This is an attempt to fix the problem.
            spid, status, rusage = os.wait3(os.WNOHANG)
26 27
            if spid == cpid:
                break
28 29
            time.sleep(1.0)

30 31 32 33 34 35
        self.assertEqual(spid, cpid)
        self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
        self.assertTrue(rusage)

def test_main():
    run_unittest(Wait3Test)
36
    reap_children()
37 38 39

if __name__ == "__main__":
    test_main()