PyDocs

Nav

Python Runtime Services

asynccontextmanager

contextlib

decorator · Added in 3.7 (source)
  • @asynccontextmanager
@asynccontextmanager decorator.

Typical usage:

    @asynccontextmanager
    async def some_async_generator(<arguments>):
        <setup>
        try:
            yield <value>
        finally:
            <cleanup>

This makes this:

    async with some_async_generator(<arguments>) as <variable>:
        <body>

equivalent to this:

    <setup>
    try:
        <variable> = <value>
        <body>
    finally:
        <cleanup>
Changed in 3.10
  • 3.10: Async context managers created with @asynccontextmanager can be used as decorators.
0 Examples
No examples for contextlib/asynccontextmanager.
See Also
No see-alsos for contextlib/asynccontextmanager
0 Notes
No notes for asynccontextmanager