Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.fork_wait.ForkWait Class Reference
Inheritance diagram for test.fork_wait.ForkWait:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def setUp
def f
def wait_impl
def test_wait

Public Attributes

 alive
 stop

Detailed Description

Definition at line 20 of file fork_wait.py.


Member Function Documentation

def test.fork_wait.ForkWait.f (   self,
  id 
)

Definition at line 26 of file fork_wait.py.

00026 
00027     def f(self, id):
00028         while not self.stop:
00029             self.alive[id] = os.getpid()
00030             try:
00031                 time.sleep(SHORTSLEEP)
00032             except IOError:
00033                 pass

Here is the caller graph for this function:

Definition at line 22 of file fork_wait.py.

00022 
00023     def setUp(self):
00024         self.alive = {}
00025         self.stop = 0

Here is the caller graph for this function:

Definition at line 46 of file fork_wait.py.

00046 
00047     def test_wait(self):
00048         for i in range(NUM_THREADS):
00049             _thread.start_new(self.f, (i,))
00050 
00051         time.sleep(LONGSLEEP)
00052 
00053         a = sorted(self.alive.keys())
00054         self.assertEqual(a, list(range(NUM_THREADS)))
00055 
00056         prefork_lives = self.alive.copy()
00057 
00058         if sys.platform in ['unixware7']:
00059             cpid = os.fork1()
00060         else:
00061             cpid = os.fork()
00062 
00063         if cpid == 0:
00064             # Child
00065             time.sleep(LONGSLEEP)
00066             n = 0
00067             for key in self.alive:
00068                 if self.alive[key] != prefork_lives[key]:
00069                     n += 1
00070             os._exit(n)
00071         else:
00072             # Parent
00073             self.wait_impl(cpid)
00074             # Tell threads to die
00075             self.stop = 1
00076             time.sleep(2*SHORTSLEEP) # Wait for threads to die

Here is the call graph for this function:

def test.fork_wait.ForkWait.wait_impl (   self,
  cpid 
)

Reimplemented in test.test_wait3.Wait3Test, test.test_fork1.ForkTest, and test.test_wait4.Wait4Test.

Definition at line 34 of file fork_wait.py.

00034 
00035     def wait_impl(self, cpid):
00036         for i in range(10):
00037             # waitpid() shouldn't hang, but some of the buildbots seem to hang
00038             # in the forking tests.  This is an attempt to fix the problem.
00039             spid, status = os.waitpid(cpid, os.WNOHANG)
00040             if spid == cpid:
00041                 break
00042             time.sleep(2 * SHORTSLEEP)
00043 
00044         self.assertEqual(spid, cpid)
00045         self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 23 of file fork_wait.py.

Definition at line 24 of file fork_wait.py.


The documentation for this class was generated from the following file: