--- id: asyncio-atexit version: "1.0.1" license: MIT License license_treatment: permissive maintenance: active --- # asyncio-atexit — Like atexit, but for asyncio License: permissive · Maintenance: active · Downloads: 671.9K/mo ## 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 above — 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 pip install asyncio-atexit uv add asyncio-atexit poetry add asyncio-atexit ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 671.9K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags asyncio cleanup on loop close, event loop atexit equivalent, asyncio shutdown handlers, register async cleanup functions, asyncio event loop exit callback, asyncio, lifecycle-management [View on SkillFed](https://skillfed.io/packages/asyncio-atexit) · [View on PyPI](https://pypi.org/project/asyncio-atexit/)