1 """This test case provides support for checking forking and wait behavior.
3 To test different wait behavior, overrise the wait_impl method.
5 We want fork1() semantics -- only the forking thread survives in the
8 On some systems (e.g. Solaris without posix threads) we find that all
9 active threads survive in the child after a fork(); this is an error.
12 import os
, sys
, time
, _thread
, unittest
18 class ForkWait(unittest
.TestCase
):
26 self
.alive
[id] = os
.getpid()
28 time
.sleep(SHORTSLEEP
)
32 def wait_impl(self
, cpid
):
34 # waitpid() shouldn't hang, but some of the buildbots seem to hang
35 # in the forking tests. This is an attempt to fix the problem.
36 spid
, status
= os
.waitpid(cpid
, os
.WNOHANG
)
39 time
.sleep(2 * SHORTSLEEP
)
41 self
.assertEquals(spid
, cpid
)
42 self
.assertEquals(status
, 0, "cause = %d, exit = %d" % (status
&0xff, status
>>8))
45 for i
in range(NUM_THREADS
):
46 _thread
.start_new(self
.f
, (i
,))
50 a
= sorted(self
.alive
.keys())
51 self
.assertEquals(a
, list(range(NUM_THREADS
)))
53 prefork_lives
= self
.alive
.copy()
55 if sys
.platform
in ['unixware7']:
64 for key
in self
.alive
:
65 if self
.alive
[key
] != prefork_lives
[key
]:
73 time
.sleep(2*SHORTSLEEP
) # Wait for threads to die