Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 02035bc

Browse files
committed
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.
1 parent 16bb419 commit 02035bc

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Lib/test/test_threading.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import threading
88
import time
99

10+
# This takes about n/3 seconds to run (about n/3 clumps of tasks, times
11+
# about 1 second per clump).
1012
numtasks = 10
1113

1214
# no more than 3 of the 10 can run at once
@@ -17,9 +19,9 @@
1719
class TestThread(threading.Thread):
1820
def run(self):
1921
global running
20-
delay = random.random() * numtasks
22+
delay = random.random() * 2
2123
if verbose:
22-
print 'task', self.getName(), 'will run for', round(delay, 1), 'sec'
24+
print 'task', self.getName(), 'will run for', delay, 'sec'
2325
sema.acquire()
2426
mutex.acquire()
2527
running = running + 1
@@ -45,8 +47,9 @@ def starttasks():
4547

4648
starttasks()
4749

48-
print 'waiting for all tasks to complete'
50+
if verbose:
51+
print 'waiting for all tasks to complete'
4952
for t in threads:
5053
t.join()
51-
print 'all tasks done'
52-
54+
if verbose:
55+
print 'all tasks done'

0 commit comments

Comments
 (0)