8000 wait_for() now accepts None as timeout · python/asyncio@6681086 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit 6681086

Browse files
committed
wait_for() now accepts None as timeout
1 parent bd1e249 commit 6681086

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

asyncio/tasks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,14 @@ def wait_for(fut, timeout, *, loop=None):
394394
if loop is None:
395395
loop = events.get_event_loop()
396396

397+
fut = async(fut, loop=loop)
398+
if timeout is None:
399+
return (yield from fut)
400+
397401
waiter = futures.Future(loop=loop)
398402
timeout_handle = loop.call_later(timeout, _release_waiter, waiter, False)
399403
cb = functools.partial(_release_waiter, waiter, True)
400404

401-
fut = async(fut, loop=loop)
402405
fut.add_done_callback(cb)
403406

404407
try:

tests/test_tasks.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,17 @@ def foo():
380380
self.assertEqual(foo_running, False)
381381

382382

383+
def test_wait_for_blocking(self):
384+
loop = test_utils.TestLoop()
385+
self.addCleanup(loop.close)
386+
387+
@asyncio.coroutine
388+
def coro():
389+
return 'done'
390+
391+
res = loop.run_until_complete(asyncio.wait_for(coro(), timeout=None, loop=loop))
392+
self.assertEqual(res, 'done')
393+
383394
def test_wait_for_with_global_loop(self):
384395

385396
def gen():

0 commit comments

Comments
 (0)
0