From 48c66c3dd82e0f345350f99d0c8713cc1e686939 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 29 Jan 2014 14:30:38 -0800 Subject: asyncio: wait_for() now accepts None as timeout (Victor Stinner). --- Lib/asyncio/tasks.py | 3 +++ Lib/test/test_asyncio/test_tasks.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index b52933f..38ffec1 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -394,6 +394,9 @@ def wait_for(fut, timeout, *, loop=None): if loop is None: loop = events.get_event_loop() + if timeout is None: + return (yield from fut) + waiter = futures.Future(loop=loop) timeout_handle = loop.call_later(timeout, _release_waiter, waiter, False) cb = functools.partial(_release_waiter, waiter, True) diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index dbf130c..778b6e0 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -380,6 +380,17 @@ class TaskTests(unittest.TestCase): self.assertEqual(foo_running, False) + def test_wait_for_blocking(self): + loop = test_utils.TestLoop() + self.addCleanup(loop.close) + + @asyncio.coroutine + def coro(): + return 'done' + + res = loop.run_until_complete(asyncio.wait_for(coro(), timeout=None, loop=loop)) + self.assertEqual(res, 'done') + def test_wait_for_with_global_loop(self): def gen(): -- cgit v0.12