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
10 # This takes about n/3 seconds to run (about n/3 clumps of tasks, times
11 # about 1 second per clump).
14 # no more than 3 of the 10 can run at once
15 sema
= threading
.BoundedSemaphore(value
=3)
16 mutex
= threading
.RLock()
19 class TestThread(threading
.Thread
):
22 delay
= random
.random() * 2
24 print 'task', self
.getName(), 'will run for', delay
, 'sec'
29 print running
, 'tasks are running'
33 print 'task', self
.getName(), 'done'
37 print self
.getName(), 'is finished.', running
, 'tasks are running'
43 for i
in range(numtasks
):
44 t
= TestThread(name
="<thread %d>"%i)
51 print 'waiting for all tasks to complete'
55 print 'all tasks done'