cpython: 5d0d488cbca8 (original) (raw)
Mercurial > cpython
changeset 68421:5d0d488cbca8 3.2
Issue #11223: Fix test_threadsignals to fail, not hang, when the non-semaphore implementation of locks is used under POSIX. [#11223]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Sun, 13 Mar 2011 19:14:21 +0100 |
parents | 4a68f4cfbdc8 |
children | f197dac00f43 eb8c2f43b251 |
files | Lib/test/test_threadsignals.py Misc/NEWS |
diffstat | 2 files changed, 20 insertions(+), 2 deletions(-)[+] [-] Lib/test/test_threadsignals.py 19 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/test/test_threadsignals.py +++ b/Lib/test/test_threadsignals.py @@ -73,18 +73,29 @@ class ThreadSignals(unittest.TestCase): def test_lock_acquire_interruption(self): # Mimic receiving a SIGINT (KeyboardInterrupt) with SIGALRM while stuck # in a deadlock.
# XXX this test can fail when the legacy (non-semaphore) implementation[](#l1.7)
# of locks is used in thread_pthread.h, see issue #11223.[](#l1.8) oldalrm = signal.signal(signal.SIGALRM, self.alarm_interrupt)[](#l1.9) try:[](#l1.10) lock = thread.allocate_lock()[](#l1.11) lock.acquire()[](#l1.12) signal.alarm(1)[](#l1.13)
self.assertRaises(KeyboardInterrupt, lock.acquire)[](#l1.14)
t1 = time.time()[](#l1.15)
self.assertRaises(KeyboardInterrupt, lock.acquire, timeout=5)[](#l1.16)
dt = time.time() - t1[](#l1.17)
# Checking that KeyboardInterrupt was raised is not sufficient.[](#l1.18)
# We want to assert that lock.acquire() was interrupted because[](#l1.19)
# of the signal, not that the signal handler was called immediately[](#l1.20)
# after timeout return of lock.acquire() (which can fool assertRaises).[](#l1.21)
self.assertLess(dt, 3.0)[](#l1.22) finally:[](#l1.23) signal.signal(signal.SIGALRM, oldalrm)[](#l1.24)
def test_rlock_acquire_interruption(self): # Mimic receiving a SIGINT (KeyboardInterrupt) with SIGALRM while stuck # in a deadlock.
# XXX this test can fail when the legacy (non-semaphore) implementation[](#l1.29)
# of locks is used in thread_pthread.h, see issue #11223.[](#l1.30) oldalrm = signal.signal(signal.SIGALRM, self.alarm_interrupt)[](#l1.31) try:[](#l1.32) rlock = thread.RLock()[](#l1.33)
@@ -98,7 +109,11 @@ class ThreadSignals(unittest.TestCase): rlock.release() time.sleep(0.01) signal.alarm(1)
self.assertRaises(KeyboardInterrupt, rlock.acquire)[](#l1.38)
t1 = time.time()[](#l1.39)
self.assertRaises(KeyboardInterrupt, rlock.acquire, timeout=5)[](#l1.40)
dt = time.time() - t1[](#l1.41)
# See rationale above in test_lock_acquire_interruption[](#l1.42)
self.assertLess(dt, 3.0)[](#l1.43) finally:[](#l1.44) signal.signal(signal.SIGALRM, oldalrm)[](#l1.45)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -92,6 +92,9 @@ Tools/Demos Tests ----- +- Issue #11223: Fix test_threadsignals to fail, not hang, when the