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

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 17deb16

Browse files
eamanumiss-islington
authored andcommitted
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
1 parent 57dc7d5 commit 17deb16

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
.. versionchanged:: 3.9

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