我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用_thread.TIMEOUT_MAX。
def test_timeout(self): lock = self.locktype() # Can't set timeout if not blocking self.assertRaises(ValueError, lock.acquire, 0, 1) # Invalid timeout values self.assertRaises(ValueError, lock.acquire, timeout=-100) self.assertRaises(OverflowError, lock.acquire, timeout=1e100) self.assertRaises(OverflowError, lock.acquire, timeout=TIMEOUT_MAX + 1) # TIMEOUT_MAX is ok lock.acquire(timeout=TIMEOUT_MAX) lock.release() t1 = time.time() self.assertTrue(lock.acquire(timeout=5)) t2 = time.time() # Just a sanity test that it didn't actually wait for the timeout. self.assertLess(t2 - t1, 5) results = [] def f(): t1 = time.time() results.append(lock.acquire(timeout=0.5)) t2 = time.time() results.append(t2 - t1) Bunch(f, 1).wait_for_finished() self.assertFalse(results[0]) self.assertTimeout(results[1], 0.5)