Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

bpo-40816 Add AsyncContextDecorator class#20516

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
asvetlov merged 12 commits intopython:masterfromheckad:fix-issue-40816
Nov 5, 2020
Merged
Changes from1 commit
Commits
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
PrevPrevious commit
NextNext commit
Update Doc/library/contextlib.rst
Co-authored-by: Yury Selivanov <yury@edgedb.com>
  • Loading branch information
@heckad@1st1
heckad and1st1 authoredOct 31, 2020
commit1293c87dedc11c85ba70c817b86c4be4318039e6
25 changes: 20 additions & 5 deletionsDoc/library/contextlib.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -126,15 +126,30 @@ Functions and classes provided:

.. versionadded:: 3.7

:func:`asynccontextmanager` uses :class:`AsyncContextDecorator` so the context managers
it creates can be used as decorators as well as in :keyword:`async with` statements.
Context managers defined with :func:`asynccontextmanager` can be used
either as decorators or with :keyword:`async with` statements::

import time

async def timeit():
now = time.monotonic()
try:
yield
finally:
print(f'it took {time.monotonic() - now}s to run')

@timeit()
async def main():
# ... async code ...

When used as a decorator, a new generator instance is implicitly created on
each function call (this allows the otherwise "one-shot" context managers
each function call. This allows the otherwise "one-shot" context managers
created by :func:`asynccontextmanager` to meet the requirement that context
managers support multiple invocations in order to be used as decorators).
managers support multiple invocations in order to be used as decorators.

.. versionchanged:: 3.10
Use of :class:`AsyncContextDecorator`.
Async context managers created with :func:`asynccontextmanager` can
be used as decorators.


.. function:: closing(thing)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp