Registry / async-exit-stack

async-exit-stack

JSON →
library1.0.1pypypi✓ verified 85d ago

A backport of AsyncExitStack from Python 3.7+ for use on Python 3.5 and 3.6. It provides an async context manager that can combine multiple async context managers and cleanup callbacks. Current version 1.0.1, release cadence is low (last release in 2018).

pip install async-exit-stack
INSTALL
IMPORT
SIG · ASYNC-EXIT-STACK
A
async-exit-stack
pythonv1.0.1
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AsyncExitStack
from async_exit_stack import AsyncExitStack
from async_exit_stack.async_exit_stack import AsyncExitStack
Common mistake: trying to import from a submodule. The package's top-level __init__.py re-exports AsyncExitStack.

Minimal example using AsyncExitStack to enter an async context manager and push a callback.

import asyncio from async_exit_stack import AsyncExitStack async def main(): async with AsyncExitStack() as stack: # enter an async context manager result = await stack.enter_async_context(some_async_context()) # push a callback stack.push_async_callback(lambda: asyncio.sleep(0)) print('Inside stack') print('Exited stack') async def some_async_context(): class FakeAsyncCM: async def __aenter__(self): return self async def __aexit__(self, *args): pass return FakeAsyncCM() asyncio.run(main())
Debug
Known issues
deprecatedThis library is a backport for Python <3.7. Python 3.5 and 3.6 are end-of-life. Use Python 3.7+'s built-in contextlib.AsyncExitStack instead.
fix
Upgrade to Python 3.7+ and use `from contextlib import AsyncExitStack`. Remove dependency on async-exit-stack.
affects: all versions
gotchaThe package is named `async-exit-stack` on PyPI, but the import module is `async_exit_stack` (underscore). Confusing these leads to ImportError.
fix
Import as `from async_exit_stack import AsyncExitStack`.
affects: all versions
gotchaAsyncExitStack.enter_context (sync) is not available; use enter_async_context. Attempting to use enter_context will raise AttributeError.
fix
Use `await stack.enter_async_context(cm)` instead of `stack.enter_context(cm)`.
affects: all versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'async_exit_stack'
Package not installed or wrong import name (confused with hyphen name).
fix
Run `pip install async-exit-stack` and then use `from async_exit_stack import AsyncExitStack`.
AttributeError: module 'async_exit_stack' has no attribute 'AsyncExitStack'
Imported the module but did not import the class correctly, e.g., `import async_exit_stack` then `async_exit_stack.AsyncExitStack` when the class is not in the module's top-level? Actually it is. More likely: installed a different package or shadowed by a local file.
fix
Ensure you have the correct package installed and no local file named async_exit_stack.py. Uninstall and reinstall: `pip uninstall async-exit-stack` and `pip install async-exit-stack`.
TypeError: object AsyncExitStack can't be used in 'await' expression
Trying to await AsyncExitStack() directly. AsyncExitStack is an async context manager, not a coroutine.
fix
Use `async with AsyncExitStack() as stack:` not `await AsyncExitStack()`.
Upgrade
Version history
1.0.1latest on PyPI · released May 7, 2018
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
async-exit-stack — pip install async-exit-stack · libregistry