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

bpo-47062: Implement asyncio.Runner context manager #31799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Mar 24, 2022
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
61f10d0
Implement Runner class
asvetlov Mar 9, 2022
d471799
Add get_loop() / new_loop() methods
asvetlov Mar 10, 2022
c68ba85
Clarify
asvetlov Mar 10, 2022
d530481
Add tests
asvetlov Mar 10, 2022
6ee7c9a
Add a comment
asvetlov Mar 10, 2022
e15d70b
Adopt IsolatedAsyncioTestCase to use Runner
asvetlov Mar 10, 2022
5c7a669
Merge branch 'main' into asyncio-runner
asvetlov Mar 10, 2022
d41988d
Merge branch 'main' into asyncio-runner
asvetlov Mar 10, 2022
8014227
Add docs sketch
asvetlov Mar 12, 2022
98e39db
Merge branch 'main' into asyncio-runner
asvetlov Mar 14, 2022
98e7a22
Add context arg to Runner.run()
asvetlov Mar 14, 2022
f4cd673
Work on docs
asvetlov Mar 17, 2022
1764045
Merge branch 'main' into asyncio-runner
asvetlov Mar 18, 2022
a443b37
Work on
asvetlov Mar 18, 2022
e6be8f7
Improve docs
asvetlov Mar 18, 2022
b1dfe4f
Add NEWS
asvetlov Mar 18, 2022
759f72a
Drop not related file
asvetlov Mar 18, 2022
f47d66a
Fix doc
asvetlov Mar 18, 2022
546440b
Update Lib/asyncio/runners.py
asvetlov Mar 18, 2022
6935f7d
Update Doc/library/asyncio-runner.rst
asvetlov Mar 18, 2022
9b9a004
Update Lib/asyncio/runners.py
asvetlov Mar 18, 2022
b0c5b8c
Improve wording
asvetlov Mar 19, 2022
599c9db
Add a test for double 'with' usage
asvetlov Mar 19, 2022
b0da74b
Improve tests
asvetlov Mar 19, 2022
04cfff9
Work on
asvetlov Mar 22, 2022
8753465
Merge branch 'main' into asyncio-runner
asvetlov Mar 22, 2022
674ad4e
Lazy init version
asvetlov Mar 22, 2022
7cd5430
Tune
asvetlov Mar 22, 2022
dd28ef7
Drop explicit get_context() function, asyncio.Task has no it also
asvetlov Mar 23, 2022
5e13b2e
Add docs for .close() method
asvetlov Mar 23, 2022
c0b999d
Add better error message for recursive run() call
asvetlov Mar 24, 2022
4937cd0
Add a note
asvetlov Mar 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add context arg to Runner.run()
  • Loading branch information
asvetlov committed Mar 14, 2022
commit 98e7a22febe137f2f090e960d0863b47ed67f00e
15 changes: 8 additions & 7 deletions 15 Lib/asyncio/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,27 @@ def close(self):
if self._loop is None:
return
try:
_cancel_all_tasks(self._loop)
self._loop.run_until_complete(self._loop.shutdown_asyncgens())
self._loop.run_until_complete(self._loop.shutdown_default_executor())
loop = self._loop
_cancel_all_tasks(loop)
loop.run_until_complete(loop.shutdown_asyncgens())
loop.run_until_complete(loop.shutdown_default_executor())
finally:
self._loop.close()
loop.close()
self._loop = None

def run(self, coro):
def run(self, coro, *, context=None):
"""Run a coroutine inside the embedded event loop."""
asvetlov marked this conversation as resolved.
Show resolved Hide resolved
if not coroutines.iscoroutine(coro):
raise ValueError("a coroutine was expected, got {!r}".format(coro))

return self._loop.run_until_complete(coro)
task = self._loop.create_task(coro, context=context)
return self._loop.run_until_complete(task)

def get_loop(self):
"""Returnb embedded event loop."""
asvetlov marked this conversation as resolved.
Show resolved Hide resolved
return self._loop



def run(main, *, debug=None):
"""Execute the coroutine and return the result.

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.