1 from test
import test_support
3 import dummy_threading
as _threading
6 class DummyThreadingTestCase(unittest
.TestCase
):
8 class TestThread(_threading
.Thread
):
14 # Uncomment if testing another module, such as the real 'threading'
16 #delay = random.random() * 2
18 if test_support
.verbose
:
19 print 'task', self
.name
, 'will run for', delay
, 'sec'
23 if test_support
.verbose
:
24 print running
, 'tasks are running'
27 if test_support
.verbose
:
28 print 'task', self
.name
, 'done'
31 if test_support
.verbose
:
32 print self
.name
, 'is finished.', running
, 'tasks are running'
39 sema
= _threading
.BoundedSemaphore(value
=3)
41 mutex
= _threading
.RLock()
47 for i
in range(self
.numtasks
):
48 t
= self
.TestThread(name
="<thread %d>"%i)
49 self
.threads
.append(t
)
52 if test_support
.verbose
:
53 print 'waiting for all tasks to complete'
54 for t
in self
.threads
:
56 if test_support
.verbose
:
57 print 'all tasks done'
60 test_support
.run_unittest(DummyThreadingTestCase
)
62 if __name__
== '__main__':