Back to index

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

List of all members.

Public Member Functions

def test_barrier
def task2
def setUp

Public Attributes

 bar
 running
 done_mutex
 running_mutex
 random_mutex
 created
 next_ident

Detailed Description

Definition at line 157 of file test_thread.py.


Member Function Documentation

def test.test_thread.BasicThreadTest.setUp (   self) [inherited]

Definition at line 25 of file test_thread.py.

00025 
00026     def setUp(self):
00027         self.done_mutex = thread.allocate_lock()
00028         self.done_mutex.acquire()
00029         self.running_mutex = thread.allocate_lock()
00030         self.random_mutex = thread.allocate_lock()
00031         self.created = 0
00032         self.running = 0
00033         self.next_ident = 0
00034 

Here is the caller graph for this function:

def test.test_thread.BarrierTest.task2 (   self,
  ident 
)

Definition at line 168 of file test_thread.py.

00168 
00169     def task2(self, ident):
00170         for i in range(NUMTRIPS):
00171             if ident == 0:
00172                 # give it a good chance to enter the next
00173                 # barrier before the others are all out
00174                 # of the current one
00175                 delay = 0
00176             else:
00177                 with self.random_mutex:
00178                     delay = random.random() / 10000.0
00179             verbose_print("task %s will run for %sus" %
00180                           (ident, round(delay * 1e6)))
00181             time.sleep(delay)
00182             verbose_print("task %s entering %s" % (ident, i))
00183             self.bar.enter()
00184             verbose_print("task %s leaving barrier" % ident)
00185         with self.running_mutex:
00186             self.running -= 1
00187             # Must release mutex before releasing done, else the main thread can
00188             # exit and set mutex to None as part of global teardown; then
00189             # mutex.release() raises AttributeError.
00190             finished = self.running == 0
00191         if finished:
00192             self.done_mutex.release()

Here is the call graph for this function:

Definition at line 159 of file test_thread.py.

00159 
00160     def test_barrier(self):
00161         self.bar = Barrier(NUMTASKS)
00162         self.running = NUMTASKS
00163         for i in range(NUMTASKS):
00164             thread.start_new_thread(self.task2, (i,))
00165         verbose_print("waiting for tasks to end")
00166         self.done_mutex.acquire()
00167         verbose_print("tasks done")


Member Data Documentation

Definition at line 160 of file test_thread.py.

Reimplemented in test.test_thread.ThreadRunningTests.

Definition at line 30 of file test_thread.py.

Definition at line 26 of file test_thread.py.

Reimplemented in test.test_thread.ThreadRunningTests.

Definition at line 32 of file test_thread.py.

Definition at line 29 of file test_thread.py.

Reimplemented from test.test_thread.BasicThreadTest.

Definition at line 161 of file test_thread.py.

Definition at line 28 of file test_thread.py.


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