annotate Lib/test/test_wait4.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents b3c0e0759ac0
children e6009b9cd908
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37099
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
1 """This test checks for correct wait4() behavior.
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
2 """
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
3
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
4 import os
39032
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
5 import time
37099
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
6 from test.fork_wait import ForkWait
38961
0a83dc3529d1 Add new utility function, reap_children(), to test_support. This should
Neal Norwitz <nnorwitz@gmail.com>
parents: 38869
diff changeset
7 from test.test_support import TestSkipped, run_unittest, reap_children
37099
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
8
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
9 try:
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
10 os.fork
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
11 except AttributeError:
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
12 raise TestSkipped, "os.fork not defined -- skipping test_wait4"
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
13
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
14 try:
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
15 os.wait4
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
16 except AttributeError:
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
17 raise TestSkipped, "os.wait4 not defined -- skipping test_wait4"
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
18
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
19 class Wait4Test(ForkWait):
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
20 def wait_impl(self, cpid):
39032
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
21 for i in range(10):
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
22 # wait4() shouldn't hang, but some of the buildbots seem to hang
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
23 # in the forking tests. This is an attempt to fix the problem.
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
24 spid, status, rusage = os.wait4(cpid, os.WNOHANG)
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
25 if spid == cpid:
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
26 break
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
27 time.sleep(1.0)
37099
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
28 self.assertEqual(spid, cpid)
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
29 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
30 self.assertTrue(rusage)
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
31
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
32 def test_main():
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
33 run_unittest(Wait4Test)
38961
0a83dc3529d1 Add new utility function, reap_children(), to test_support. This should
Neal Norwitz <nnorwitz@gmail.com>
parents: 38869
diff changeset
34 reap_children()
37099
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
35
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
36 if __name__ == "__main__":
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
37 test_main()