Commit 02035bc6 authored by Tim Peters's avatar Tim Peters

Test failed because these was no expected-output file, but always printed

to stdout.  Repaired by not printing at all except in verbose mode.

Made the test about 6x faster -- envelope analysis showed it took time
proportional to the square of the # of tasks.  Now it's linear.
parent 16bb4193
...@@ -7,6 +7,8 @@ import random ...@@ -7,6 +7,8 @@ import random
import threading import threading
import time import time
# This takes about n/3 seconds to run (about n/3 clumps of tasks, times
# about 1 second per clump).
numtasks = 10 numtasks = 10
# no more than 3 of the 10 can run at once # no more than 3 of the 10 can run at once
...@@ -17,9 +19,9 @@ running = 0 ...@@ -17,9 +19,9 @@ running = 0
class TestThread(threading.Thread): class TestThread(threading.Thread):
def run(self): def run(self):
global running global running
delay = random.random() * numtasks delay = random.random() * 2
if verbose: if verbose:
print 'task', self.getName(), 'will run for', round(delay, 1), 'sec' print 'task', self.getName(), 'will run for', delay, 'sec'
sema.acquire() sema.acquire()
mutex.acquire() mutex.acquire()
running = running + 1 running = running + 1
...@@ -45,8 +47,9 @@ def starttasks(): ...@@ -45,8 +47,9 @@ def starttasks():
starttasks() starttasks()
print 'waiting for all tasks to complete' if verbose:
print 'waiting for all tasks to complete'
for t in threads: for t in threads:
t.join() t.join()
print 'all tasks done' if verbose:
print 'all tasks done'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment