summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-08-20 21:45:19 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-08-20 21:45:19 (GMT)
commit02035bc68d99e291e4c41ea0ea17536bb4ea95b9 (patch)
treeb306dcabc0ae3438c1f4450f6de92e016b365a13 /Lib/test/test_threading.py
parent16bb41934c1258282170e7773e36fe7ffad3cfdc (diff)
downloadcpython-02035bc68d99e291e4c41ea0ea17536bb4ea95b9.zip
cpython-02035bc68d99e291e4c41ea0ea17536bb4ea95b9.tar.gz
cpython-02035bc68d99e291e4c41ea0ea17536bb4ea95b9.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 87262b1..5230117 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -7,6 +7,8 @@ import random
import threading
import time
+# This takes about n/3 seconds to run (about n/3 clumps of tasks, times
+# about 1 second per clump).
numtasks = 10
# no more than 3 of the 10 can run at once
@@ -17,9 +19,9 @@ running = 0
class TestThread(threading.Thread):
def run(self):
global running
- delay = random.random() * numtasks
+ delay = random.random() * 2
if verbose:
- print 'task', self.getName(), 'will run for', round(delay, 1), 'sec'
+ print 'task', self.getName(), 'will run for', delay, 'sec'
sema.acquire()
mutex.acquire()
running = running + 1
@@ -45,8 +47,9 @@ def starttasks():
starttasks()
-print 'waiting for all tasks to complete'
+if verbose:
+ print 'waiting for all tasks to complete'
for t in threads:
t.join()
-print 'all tasks done'
-
+if verbose:
+ print 'all tasks done'