Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.rst

AsyncExitStack backport for Python 3.5+

This package contains code from the CPython project.

Install

pip install async_exit_stack

Usage example

from async_exit_stack import AsyncExitStack

async def some_async_function():
    async with AsyncExitStack() as stack:
        connections = [await stack.enter_async_context(get_connection())
            for i in range(5)]
        # All opened connections will automatically be released at the end of
        # the async with statement, even if attempts to open a connection
        # later in the list raise an exception.

Reference

Refer to Python 3.7 contextlib documentation for a complete reference and more context.

class AsyncExitStack

An asynchronous context manager, similar to ExitStack, that supports combining both synchronous and asynchronous context managers, as well as having coroutines for cleanup logic.

The close() method is not implemented, aclose() must be used instead.

enter_async_context(cm)
Similar to enter_context() but expects an asynchronous context manager.
push_async_exit(exit)
Similar to push() but expects either an asynchronous context manager or a coroutine.
push_async_callback(callback, *args, **kwds)
Similar to callback() but expects a coroutine.
aclose()
Similar to close() but properly handles awaitables.

About

AsyncExitStack backport for Python 3.5+

Topics

Resources

License

Packages

No packages published
You can’t perform that action at this time.