AsyncExitStack backport for Python 3.5+
Project description
AsyncExitStack backport for Python 3.5+
Free software: PSF license
Documentation: https://docs.python.org/3.7/library/contextlib.html#contextlib.AsyncExitStack
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.
History
1.0.0 (2018-05-07)
First release based on Python 3.7b4.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file async_exit_stack-1.0.1.tar.gz
.
File metadata
- Download URL: async_exit_stack-1.0.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24de1ad6d0ff27be97c89d6709fa49bf20db179eaf1f4d2e6e9b4409b80e747d |
|
MD5 | 4c16d3ac6243ed086ab7a9c7266f013b |
|
BLAKE2b-256 | 339cecf37497cd8c4aa6d62de0a67deeb80d4407fd930a689362e588458aff81 |
File details
Details for the file async_exit_stack-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: async_exit_stack-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b43b17683b3438f428ef3bbec20689f5abbb052aa4b564c643397330adfaa99 |
|
MD5 | 992cd0802def9ac79440268348a0387b |
|
BLAKE2b-256 | 77aef5baabf02fe19c4015b0417e72e36220fb95ed3e7cf17e8a85004b964709 |