mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
asyncio: allow None as wait timeout
Fix GH#325: Allow to pass None as a timeout value to disable timeout logic. Change written by Andrew Svetlov and merged by Guido van Rossum.
This commit is contained in:
parent
ccdbe80a56
commit
2ba8ece5be
2 changed files with 24 additions and 6 deletions
|
@ -2382,6 +2382,22 @@ class TimeoutTests(test_utils.TestCase):
|
|||
|
||||
self.loop.run_until_complete(go())
|
||||
|
||||
def test_timeout_disable(self):
|
||||
@asyncio.coroutine
|
||||
def long_running_task():
|
||||
yield from asyncio.sleep(0.1, loop=self.loop)
|
||||
return 'done'
|
||||
|
||||
@asyncio.coroutine
|
||||
def go():
|
||||
t0 = self.loop.time()
|
||||
with asyncio.timeout(None, loop=self.loop):
|
||||
resp = yield from long_running_task()
|
||||
self.assertEqual(resp, 'done')
|
||||
dt = self.loop.time() - t0
|
||||
self.assertTrue(0.09 < dt < 0.11, dt)
|
||||
self.loop.run_until_complete(go())
|
||||
|
||||
def test_raise_runtimeerror_if_no_task(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
with asyncio.timeout(0.1, loop=self.loop):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue