summaryrefslogtreecommitdiff
path: root/Lib/test/test_thread.py
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2008-03-18 04:56:06 +0000
committerJeffrey Yasskin <jyasskin@gmail.com>2008-03-18 04:56:06 +0000
commita14585308af777aa64ec7100472d3c3e2961a6e7 (patch)
tree08cdd0a5d65186ee96690ba627c6997d2fa2b00e /Lib/test/test_thread.py
parentb1d3d96374294904a13717403c80035718331092 (diff)
downloadcpython-git-a14585308af777aa64ec7100472d3c3e2961a6e7.tar.gz
Speed test_thread up from 51.328s to 0.081s by reducing its sleep times. We
still sleep at all to make it likely that all threads are active at the same time.
Diffstat (limited to 'Lib/test/test_thread.py')
-rw-r--r--Lib/test/test_thread.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py
index f0d66c75c1..ffd5244426 100644
--- a/Lib/test/test_thread.py
+++ b/Lib/test/test_thread.py
@@ -10,10 +10,13 @@ NUMTASKS = 10
NUMTRIPS = 3
+_print_mutex = thread.allocate_lock()
+
def verbose_print(arg):
"""Helper function for printing out debugging output."""
if test_support.verbose:
- print arg
+ with _print_mutex:
+ print arg
class BasicThreadTest(unittest.TestCase):
@@ -38,8 +41,8 @@ class ThreadRunningTests(BasicThreadTest):
def task(self, ident):
with self.random_mutex:
- delay = random.random() * NUMTASKS
- verbose_print("task %s will run for %s" % (ident, round(delay, 1)))
+ delay = random.random() / 10000.0
+ verbose_print("task %s will run for %sus" % (ident, round(delay*1e6)))
time.sleep(delay)
verbose_print("task %s done" % ident)
with self.running_mutex:
@@ -138,11 +141,12 @@ class BarrierTest(BasicThreadTest):
# give it a good chance to enter the next
# barrier before the others are all out
# of the current one
- delay = 0.001
+ delay = 0
else:
with self.random_mutex:
- delay = random.random() * NUMTASKS
- verbose_print("task %s will run for %s" % (ident, round(delay, 1)))
+ delay = random.random() / 10000.0
+ verbose_print("task %s will run for %sus" %
+ (ident, round(delay * 1e6)))
time.sleep(delay)
verbose_print("task %s entering %s" % (ident, i))
self.bar.enter()