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
# of locks is used in thread_pthread.h, see issue #11223.
oldalrm = signal.signal(signal.SIGALRM, self.alarm_interrupt)
try:
rlock = thread.RLock()
# For reentrant locks, the initial acquisition must be in another
# thread.
def other_thread():
rlock.acquire()
thread.start_new_thread(other_thread, ())
# Wait until we can't acquire it without blocking...
while rlock.acquire(blocking=False):
rlock.release()
time.sleep(0.01)
signal.alarm(1)
t1 = time.time()
self.assertRaises(KeyboardInterrupt, rlock.acquire, timeout=5)
dt = time.time() - t1
# See rationale above in test_lock_acquire_interruption
self.assertLess(dt, 3.0)
finally:
signal.signal(signal.SIGALRM, oldalrm)
评论列表
文章目录