asyncio-atexit
Like atexit, but for asyncio
What it is and what it does
asyncio-atexit fills a gap in asyncio's lifecycle management by providing a way to register coroutines and synchronous functions that run when an event loop closes. The standard library's atexit module registers functions to run at interpreter shutdown, but asyncio applications often need cleanup tied to the event loop's lifecycle instead—for example, closing database connections or flushing buffers when a specific loop terminates. This package lets you register those handlers and have them called automatically.
The package accepts both async and sync functions, and they are invoked when loop.close() is called. It's a thin, focused tool: no dependencies, works with Python 3.6 and later, and integrates directly into asyncio's shutdown sequence. The main constraint is that cleanup only runs if your application explicitly closes the loop—it won't trigger on implicit cleanup or if the loop is abandoned.
Use it for:
- Close database or cache connections when an asyncio application's event loop shuts down
- Flush pending writes or cleanup temporary resources in async server applications
- Register teardown logic in async test fixtures that need to run after each event loop
- Clean up external resources (files, network sockets) tied to a specific event loop instance
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Registers cleanup functions to run when an asyncio event loop closes, similar to the standard library's atexit but tied to event loop lifecycle rather than interpreter exit.
Yes, if you need event-loop-scoped cleanup in asyncio applications. Install friction is minimal and the license is permissive. The main caveat: the package has not been updated since 2022-04-26, so verify compatibility with your Python version and test that cleanup runs as expected in your specific event loop setup. No known vulnerabilities.
Install
asyncio-atexit on PyPI
pip
pip install asyncio-atexituv
uv add asyncio-atexitpoetry
poetry add asyncio-atexitInstalling asyncio-atexit
Before you install
Low friction: pure Python wheel with no runtime dependencies. Maintenance is active with recent commits, though the package itself has not been updated since 2022-04-26.
License in practice
MIT License (permissive) — you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install asyncio-atexit
import asyncio_atexit
async def cleanup():
print('Cleaning up')
asyncio_atexit.register(cleanup)
# cleanup() runs when the event loop closes
Must be called from within a running event loop, and cleanup only runs if the application explicitly calls loop.close()
Verify before relying
- Whether the package works correctly with modern Python versions beyond 3.6, given no release since 2022
- Behavior when multiple event loops are created in the same process
- Performance impact of the registration mechanism under high-volume cleanup scenarios
Package facts
| License | MIT License (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 1,571 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 671,892/month — #5,403 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: asyncio_atexit-1.0.1-py3-none-any.whl
Keywords: asyncio
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
aiorunProvides a simplified entry point for asyncio…
permissive · top 15,000 on PyPI
async-exit-stackProvides AsyncExitStack, a backport of Python…
permissive · top 15,000 on PyPI
asyncioThis package is an obsolete backport of…
permissive · top 1,000 on PyPI
qasyncqasync integrates asyncio coroutines into…
permissive · top 15,000 on PyPI
aioprocessingProvides asyncio-compatible wrappers around…
permissive · top 15,000 on PyPI
syncerSyncer converts async functions to synchronous…
permissive · top 15,000 on PyPI
asynctestExtends Python's unittest module with test…
permissive · top 5,000 on PyPI
nest-asyncio2Patches asyncio to allow nested event loops,…
permissive · top 1,000 on PyPI
aiomultiprocessCombines AsyncIO and multiprocessing to run…
permissive · top 5,000 on PyPI
aiosignalProvides a Signal class for managing lists of…
permissive · top 100 on PyPI