1 """This test case provides support for checking forking and wait behavior.
3 To test different wait behavior, override 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.
11 While BeOS doesn't officially support fork and native threading in
12 the same application, the present example should work just fine. DC
15 import os
, sys
, time
, unittest
16 import test
.test_support
as test_support
17 thread
= test_support
.import_module('thread')
23 class ForkWait(unittest
.TestCase
):
31 self
.alive
[id] = os
.getpid()
33 time
.sleep(SHORTSLEEP
)
37 def wait_impl(self
, cpid
):
39 # waitpid() shouldn't hang, but some of the buildbots seem to hang
40 # in the forking tests. This is an attempt to fix the problem.
41 spid
, status
= os
.waitpid(cpid
, os
.WNOHANG
)
44 time
.sleep(2 * SHORTSLEEP
)
46 self
.assertEquals(spid
, cpid
)
47 self
.assertEquals(status
, 0, "cause = %d, exit = %d" % (status
&0xff, status
>>8))
50 for i
in range(NUM_THREADS
):
51 thread
.start_new(self
.f
, (i
,))
57 self
.assertEquals(a
, range(NUM_THREADS
))
59 prefork_lives
= self
.alive
.copy()
61 if sys
.platform
in ['unixware7']:
70 for key
in self
.alive
:
71 if self
.alive
[key
] != prefork_lives
[key
]:
79 time
.sleep(2*SHORTSLEEP
) # Wait for threads to die