summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_thread.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1996-12-16 23:42:35 (GMT)
committerBarry Warsaw <barry@python.org>1996-12-16 23:42:35 (GMT)
commitaf0a1a65308eee025c2a25d218d3de48de4d6a83 (patch)
tree5963c114ff2eee795fc2527dab10b06458b675aa /Lib/test/test_thread.py
parent63a0c376ea97ca614e6b8c0cf847343e5e96377b (diff)
downloadcpython-af0a1a65308eee025c2a25d218d3de48de4d6a83.zip
cpython-af0a1a65308eee025c2a25d218d3de48de4d6a83.tar.gz
cpython-af0a1a65308eee025c2a25d218d3de48de4d6a83.tar.bz2
(test_thread.py): modifications to quiet it up when not running as a script.
(testall.py): added test_thread to the list of regression tests.
Diffstat (limited to 'Lib/test/test_thread.py')
-rw-r--r--Lib/test/test_thread.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py
index 4e0eb70..f5e5057 100644
--- a/Lib/test/test_thread.py
+++ b/Lib/test/test_thread.py
@@ -6,6 +6,10 @@ import whrandom
import thread
import time
+verbose = 0
+if __name__ == '__main__':
+ verbose = 1
+
mutex = thread.allocate_lock()
whmutex = thread.allocate_lock() # for calls to whrandom
running = 0
@@ -19,9 +23,11 @@ def task(ident):
whmutex.acquire()
delay = whrandom.random() * numtasks
whmutex.release()
- print 'task', ident, 'will run for', delay, 'sec'
+ if verbose:
+ print 'task', ident, 'will run for', delay, 'sec'
time.sleep(delay)
- print 'task', ident, 'done'
+ if verbose:
+ print 'task', ident, 'done'
mutex.acquire()
running = running - 1
if running == 0:
@@ -33,7 +39,8 @@ def newtask():
global next_ident, running
mutex.acquire()
next_ident = next_ident + 1
- print 'creating task', next_ident
+ if verbose:
+ print 'creating task', next_ident
thread.start_new_thread(task, (next_ident,))
running = running + 1
mutex.release()
@@ -84,11 +91,14 @@ def task2(ident):
whmutex.acquire()
delay = whrandom.random() * numtasks
whmutex.release()
- print 'task', ident, 'will run for', delay, 'sec'
+ if verbose:
+ print 'task', ident, 'will run for', delay, 'sec'
time.sleep(delay)
- print 'task', ident, 'entering barrier', i
+ if verbose:
+ print 'task', ident, 'entering barrier', i
bar.enter()
- print 'task', ident, 'leaving barrier', i
+ if verbose:
+ print 'task', ident, 'leaving barrier', i
mutex.acquire()
running = running - 1
if running == 0: