python - Is there a difference between 'await future' and 'await asyncio.wait_for(future, None)'? -


with python 3.5 or later, there difference between directly applying await future or task, , wrapping asyncio.wait_for? documentation unclear on when appropriate use wait_for , i'm wondering if it's vestige of old generator-based library. test program below appears show no difference doesn't prove anything.

import asyncio  async def task_one():     await asyncio.sleep(0.1)     return 1  async def task_two():     await asyncio.sleep(0.1)     return 2  async def test(loop):     t1 = loop.create_task(task_one())     t2 = loop.create_task(task_two())      print(repr(await t1))     print(repr(await asyncio.wait_for(t2, none)))  def main():     loop = asyncio.get_event_loop()     try:         loop.run_until_complete(test(loop))     finally:         loop.close()  main() 

unfortunately python documentation little bit unclear here, if have sources pretty obvious:

in contrary await coroutine asyncio.wait_for() allows wait limited time until future/task completes. if not complete within time concurrent.futures.timeouterror raised.

this timeout can specified second parameter. in sample code timeout parameter none results in exactly same functionality directly applying await/yield from.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -