summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-03-22 00:47:35 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-03-22 00:47:35 (GMT)
commit4fbc72b4ac7ac32d85f1fe8d465ed4c8736d002d (patch)
treebe5ea38e3ef6d53046f90b35d1ea7d0f077aed87 /Lib/test/test_threading.py
parent73a22f0500ce713d46fce864e95402c34a45afd9 (diff)
downloadcpython-4fbc72b4ac7ac32d85f1fe8d465ed4c8736d002d.zip
cpython-4fbc72b4ac7ac32d85f1fe8d465ed4c8736d002d.tar.gz
cpython-4fbc72b4ac7ac32d85f1fe8d465ed4c8736d002d.tar.bz2
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r61687 | jeffrey.yasskin | 2008-03-21 06:02:44 +0100 (Fri, 21 Mar 2008) | 2 lines Speed up test_signal from ~24s to 4s by avoiding nearly all of the sleep calls. ........ r61688 | jeffrey.yasskin | 2008-03-21 06:51:37 +0100 (Fri, 21 Mar 2008) | 5 lines Try to fix test_signal breakages on Linux due to r61687. It appears that at least two of the linux build bots aren't leaving zombie processes around for os.waitpid to wait for, causing ECHILD errors. This would be a symptom of a bug somewhere, but probably not in signal itself. ........ r61696 | georg.brandl | 2008-03-21 15:32:33 +0100 (Fri, 21 Mar 2008) | 2 lines Mark the descitems in the tutorial as "noindex" so that :meth: cross-refs don't link to them. ........ r61700 | georg.brandl | 2008-03-21 18:19:29 +0100 (Fri, 21 Mar 2008) | 2 lines Fix markup. ........ r61704 | jeffrey.yasskin | 2008-03-21 19:25:06 +0100 (Fri, 21 Mar 2008) | 3 lines Try to fix test_signal on FreeBSD. I'm assuming that os.kill is failing to raise a signal, but switching to subprocess makes the code cleaner anyway. ........ r61705 | jeffrey.yasskin | 2008-03-21 19:48:04 +0100 (Fri, 21 Mar 2008) | 7 lines Speed test_threading up from 14s to .5s, and avoid a deadlock on certain failures. The test for enumerate-after-join is now a little less rigorous, but the bug it references says the error happened in the first couple iterations, so 100 iterations should still be enough. cProfile was useful for identifying the slow tests here. ........ r61707 | georg.brandl | 2008-03-21 20:14:38 +0100 (Fri, 21 Mar 2008) | 2 lines Fix a code block in __future__ docs. ........ r61708 | georg.brandl | 2008-03-21 20:20:21 +0100 (Fri, 21 Mar 2008) | 2 lines Add docs for __func__ and __self__ on methods. ........ r61709 | georg.brandl | 2008-03-21 20:37:57 +0100 (Fri, 21 Mar 2008) | 2 lines Add docs for print_function and future_builtins. Fixes #2442. ........ r61711 | georg.brandl | 2008-03-21 20:54:00 +0100 (Fri, 21 Mar 2008) | 2 lines #2136: allow single quotes in realm spec. ........ r61712 | georg.brandl | 2008-03-21 21:01:51 +0100 (Fri, 21 Mar 2008) | 3 lines Issue #2432: give DictReader the dialect and line_num attributes advertised in the docs. ........ r61714 | georg.brandl | 2008-03-21 21:11:46 +0100 (Fri, 21 Mar 2008) | 2 lines #2358: add py3k warning to sys.exc_clear(). ........ r61715 | georg.brandl | 2008-03-21 21:21:46 +0100 (Fri, 21 Mar 2008) | 2 lines #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich. ........ r61716 | georg.brandl | 2008-03-21 21:38:24 +0100 (Fri, 21 Mar 2008) | 2 lines #2348: add py3k warning for file.softspace. ........ r61718 | georg.brandl | 2008-03-21 21:55:20 +0100 (Fri, 21 Mar 2008) | 2 lines #2160: document PyImport_GetImporter. ........ r61719 | georg.brandl | 2008-03-21 21:55:51 +0100 (Fri, 21 Mar 2008) | 2 lines Update doc ACKS. ........ r61720 | steven.bethard | 2008-03-21 22:01:18 +0100 (Fri, 21 Mar 2008) | 1 line Replace hack in regrtest.py with use of sys.py3kwarning. ........ r61721 | georg.brandl | 2008-03-21 22:05:03 +0100 (Fri, 21 Mar 2008) | 2 lines Add missing versionadded tag. ........ r61722 | christian.heimes | 2008-03-22 00:49:44 +0100 (Sat, 22 Mar 2008) | 3 lines Applied patch #1657 epoll and kqueue wrappers for the select module The patch adds wrappers for the Linux epoll syscalls and the BSD kqueue syscalls. Thanks to Thomas Herve and the Twisted people for their support and help. TODO: Finish documentation documentation ........
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py46
1 files changed, 22 insertions, 24 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 3d5c120..67d9ed9 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -30,32 +30,26 @@ class TestThread(threading.Thread):
self.nrunning = nrunning
def run(self):
- delay = random.random() * 2
+ delay = random.random() / 10000.0
if verbose:
print('task', self.getName(), 'will run for', delay, 'sec')
- self.sema.acquire()
+ with self.sema:
+ with self.mutex:
+ self.nrunning.inc()
+ if verbose:
+ print(self.nrunning.get(), 'tasks are running')
+ self.testcase.assert_(self.nrunning.get() <= 3)
- self.mutex.acquire()
- self.nrunning.inc()
- if verbose:
- print(self.nrunning.get(), 'tasks are running')
- self.testcase.assert_(self.nrunning.get() <= 3)
- self.mutex.release()
-
- time.sleep(delay)
- if verbose:
- print('task', self.getName(), 'done')
-
- self.mutex.acquire()
- self.nrunning.dec()
- self.testcase.assert_(self.nrunning.get() >= 0)
- if verbose:
- print(self.getName(), 'is finished.', self.nrunning.get(), \
- 'tasks are running')
- self.mutex.release()
-
- self.sema.release()
+ time.sleep(delay)
+ if verbose:
+ print('task', self.getName(), 'done')
+ with self.mutex:
+ self.nrunning.dec()
+ self.testcase.assert_(self.nrunning.get() >= 0)
+ if verbose:
+ print('%s is finished. %d tasks are running' %
+ self.getName(), self.nrunning.get())
class ThreadTests(unittest.TestCase):
@@ -218,6 +212,10 @@ class ThreadTests(unittest.TestCase):
rc = subprocess.call([sys.executable, "-c", """if 1:
import ctypes, sys, time, thread
+ # This lock is used as a simple event variable.
+ ready = thread.allocate_lock()
+ ready.acquire()
+
# Module globals are cleared before __del__ is run
# So we save the functions in class dict
class C:
@@ -229,10 +227,11 @@ class ThreadTests(unittest.TestCase):
def waitingThread():
x = C()
+ ready.release()
time.sleep(100)
thread.start_new_thread(waitingThread, ())
- time.sleep(1) # be sure the other thread is waiting
+ ready.acquire() # Be sure the other thread is waiting.
sys.exit(42)
"""])
self.assertEqual(rc, 42)
@@ -242,7 +241,6 @@ class ThreadTests(unittest.TestCase):
# threading.enumerate() after it has been join()ed.
enum = threading.enumerate
old_interval = sys.getcheckinterval()
- sys.setcheckinterval(1)
try:
for i in range(1, 1000):
t = threading.Thread(target=lambda: None)