Skip to content

Commit

Permalink
Add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
heckad committed Jul 23, 2020
1 parent a5fd929 commit a1735c5
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Doc/library/contextlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,43 @@ Functions and classes provided:
.. versionadded:: 3.2


.. class:: AsyncContextManager

Similar as ContextManger only for async

Example of ``ContextDecorator``::
from asyncio import run
from contextlib import AsyncContextDecorator

class mycontext(AsyncContextDecorator):
async def __aenter__(self):
print('Starting')
return self

async def __aexit__(self, *exc):
print('Finishing')
return False

>>> @mycontext()
... async def function():
... print('The bit in the middle')
...
>>> run(function())
Starting
The bit in the middle
Finishing

>>> async def function():
... async with mycontext():
... print('The bit in the middle')
...
>>> run(function())
Starting
The bit in the middle
Finishing


.. class:: ExitStack()

A context manager that is designed to make it easy to programmatically
Expand Down

0 comments on commit a1735c5

Please sign in to comment.