8000 bpo-38260: Add Docs on asyncio.run (GH-16337) · python/cpython@4633355 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4633355

Browse files
bpo-38260: Add Docs on asyncio.run (GH-16337)
Add docs about return and raise exception on asyncio.run https://bugs.python.org/issue38260 Automerge-Triggered-By: @asvetlov (cherry picked from commit 17deb16) Co-authored-by: Emmanuel Arias <emmanuelarias30@gmail.com>
1 parent ce62dcc commit 4633355

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Doc/library/asyncio-task.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,18 @@ Running an asyncio Program
225225
the end. It should be used as a main entry point for asyncio
226226
programs, and should ideally only be called once.
227227

228+
Return a result of *coro* execution, or raise a :exc:`RuntimeError`
229+
if ``asyncio.run()`` is called from a running event loop, or a
230+
:exc:`ValueError` if *coro* is not a courutine.
231+
232+
Example::
233+
234+
async def main():
235+
await asyncio.sleep(1)
236+
print('hello')
237+
238+
asyncio.run(main())
239+
228240
.. versionadded:: 3.7
229241

230242

Lib/asyncio/runners.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def run(main, *, debug=False):
2121
It should be used as a main entry point for asyncio programs, and should
2222
ideally only be called once.
2323
24+
Return a result of *coro* execution, or raise a RuntimeError
25+
if `asyncio.run()`is called from a running event loop, or a ValueError
26+
if `main` is not a courutine.
27+
2428
Example:
2529
2630
async def main():

0 commit comments

Comments
 (0)
0