From 39cd32b8ef5f7796b434afead7099402e4fbaa3f Mon Sep 17 00:00:00 2001 From: eamanu Date: Mon, 23 Sep 2019 18:02:28 -0300 Subject: [PATCH 1/3] Add Docs on asyncio.run Add docs about return and raise exception on asyncio.run --- Doc/library/asyncio-task.rst | 13 +++++++++++++ Lib/asyncio/runners.py | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index 1fb88293589518..212ec2c2dab55e 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -225,6 +225,19 @@ Running an asyncio Program the end. It should be used as a main entry point for asyncio programs, and should ideally only be called once. + Return the `base_events.run_until_complete()` that this return the + Future's result, or raise a RuntimeError if `asyncio.run()`is called + from a running event loop, or a ValueError if `main` is not a + courutine. + + Example:: + + async def main(): + await asyncio.sleep(1) + print('hello') + + asyncio.run(main()) + .. versionadded:: 3.7 .. versionchanged:: 3.9 diff --git a/Lib/asyncio/runners.py b/Lib/asyncio/runners.py index 6c87747e770bb8..f4ff87c3b617b5 100644 --- a/Lib/asyncio/runners.py +++ b/Lib/asyncio/runners.py @@ -21,6 +21,11 @@ def run(main, *, debug=False): It should be used as a main entry point for asyncio programs, and should ideally only be called once. + Return the `base_events.run_until_complete()` that this return the + Future's result, or raise a RuntimeError if `asyncio.run()`is called + from a running event loop, or a ValueError if `main` is not a + courutine. + Example: async def main(): From 1ba3164357779938094e719e2d975e4fb653d1c2 Mon Sep 17 00:00:00 2001 From: Emmanuel Arias Date: Mon, 23 Sep 2019 19:12:15 -0300 Subject: [PATCH 2/3] Fix documentation according to @asvetlov --- Doc/library/asyncio-task.rst | 7 +++---- Lib/asyncio/runners.py | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index 212ec2c2dab55e..477e92c84ffe5b 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -225,10 +225,9 @@ Running an asyncio Program the end. It should be used as a main entry point for asyncio programs, and should ideally only be called once. - Return the `base_events.run_until_complete()` that this return the - Future's result, or raise a RuntimeError if `asyncio.run()`is called - from a running event loop, or a ValueError if `main` is not a - courutine. + Return a result of *coro* execution, or raise a RuntimeError if + ``asyncio.run()`` is called from a running event loop, or a + ValueError if *coro* is not a courutine. Example:: diff --git a/Lib/asyncio/runners.py b/Lib/asyncio/runners.py index f4ff87c3b617b5..904102bf82bef4 100644 --- a/Lib/asyncio/runners.py +++ b/Lib/asyncio/runners.py @@ -21,10 +21,9 @@ def run(main, *, debug=False): It should be used as a main entry point for asyncio programs, and should ideally only be called once. - Return the `base_events.run_until_complete()` that this return the - Future's result, or raise a RuntimeError if `asyncio.run()`is called - from a running event loop, or a ValueError if `main` is not a - courutine. + Return a result of *coro* execution, or raise a RuntimeError + if `asyncio.run()`is called from a running event loop, or a ValueError + if `main` is not a courutine. Example: From 9dc8cb373bc1f6c22ceb33ac00acf822ad5ba484 Mon Sep 17 00:00:00 2001 From: eamanu Date: Wed, 25 Sep 2019 00:31:45 -0300 Subject: [PATCH 3/3] Add @corona10 comments --- Doc/library/asyncio-task.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index 477e92c84ffe5b..9f55a3534a5e0c 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -225,9 +225,9 @@ Running an asyncio Program the end. It should be used as a main entry point for asyncio programs, and should ideally only be called once. - Return a result of *coro* execution, or raise a RuntimeError if - ``asyncio.run()`` is called from a running event loop, or a - ValueError if *coro* is not a courutine. + Return a result of *coro* execution, or raise a :exc:`RuntimeError` + if ``asyncio.run()`` is called from a running event loop, or a + :exc:`ValueError` if *coro* is not a courutine. Example::