1 # Very rudimentary test of threading module
3 # Create a bunch of threads, let each do some work, wait until all are done
5 from test
.test_support
import verbose
7 import dummy_threading
as _threading
11 class TestThread(_threading
.Thread
):
15 # Uncomment if testing another module, such as the real 'threading'
17 #delay = random.random() * 2
20 print 'task', self
.getName(), 'will run for', delay
, 'sec'
25 print running
, 'tasks are running'
29 print 'task', self
.getName(), 'done'
33 print self
.getName(), 'is finished.', running
, 'tasks are running'
38 for i
in range(numtasks
):
39 t
= TestThread(name
="<thread %d>"%i)
45 # This takes about n/3 seconds to run (about n/3 clumps of tasks, times
46 # about 1 second per clump).
50 # no more than 3 of the 10 can run at once
52 sema
= _threading
.BoundedSemaphore(value
=3)
54 mutex
= _threading
.RLock()
64 print 'waiting for all tasks to complete'
68 print 'all tasks done'
72 if __name__
== '__main__':