annotate Lib/test/test_fork1.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents f4c5e3a64be2
children b0d03fa073ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11855
79ea19085fb6 Test case for fork1() behavior.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 """This test checks for correct fork() behavior.
79ea19085fb6 Test case for fork1() behavior.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 """
79ea19085fb6 Test case for fork1() behavior.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
37099
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents: 24366
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: 24366
diff changeset
6 from test.fork_wait import ForkWait
52491
f4c5e3a64be2 Change more tests to use import_module for the modules that
R. David Murray <rdmurray@bitdance.com>
parents: 52456
diff changeset
7 from test.test_support import run_unittest, reap_children, get_attribute
11855
79ea19085fb6 Test case for fork1() behavior.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
52456
f2c90fd05d66 Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents: 52440
diff changeset
9 #Skip test if fork does not exist.
52491
f4c5e3a64be2 Change more tests to use import_module for the modules that
R. David Murray <rdmurray@bitdance.com>
parents: 52456
diff changeset
10 get_attribute(os, 'fork')
52456
f2c90fd05d66 Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents: 52440
diff changeset
11
12578
077456c324bc Raise ImportError when os.fork does not exist.
Guido van Rossum <guido@python.org>
parents: 12470
diff changeset
12
37099
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents: 24366
diff changeset
13 class ForkTest(ForkWait):
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents: 24366
diff changeset
14 def wait_impl(self, cpid):
39032
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
15 for i in range(10):
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
16 # waitpid() shouldn't hang, but some of the buildbots seem to hang
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
17 # 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
18 spid, status = os.waitpid(cpid, os.WNOHANG)
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
19 if spid == cpid:
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
20 break
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
21 time.sleep(1.0)
b3c0e0759ac0 Restore rev 47014:
Neal Norwitz <nnorwitz@gmail.com>
parents: 38961
diff changeset
22
37099
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents: 24366
diff changeset
23 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: 24366
diff changeset
24 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
12332
6b4667fa4938 Use a constant to specify the number of child threads to create.
Fred Drake <fdrake@acm.org>
parents: 11855
diff changeset
25
37099
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents: 24366
diff changeset
26 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: 24366
diff changeset
27 run_unittest(ForkTest)
38961
0a83dc3529d1 Add new utility function, reap_children(), to test_support. This should
Neal Norwitz <nnorwitz@gmail.com>
parents: 38869
diff changeset
28 reap_children()
11855
79ea19085fb6 Test case for fork1() behavior.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
37099
d62b13488943 Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents: 24366
diff changeset
30 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: 24366
diff changeset
31 test_main()