--- id: async-interrupt version: "1.2.2" license: Apache-2.0 license_treatment: permissive maintenance: active --- # async-interrupt — Context manager to raise an exception when a future is done License: permissive · Maintenance: active · Downloads: 907.8K/mo ## What it is and what it does async_interrupt is a lightweight asyncio utility that provides a context manager for raising an exception as soon as a future completes. It wraps a code block and monitors a supplied future; when that future is done, the context manager raises a specified exception with an optional message. The design prioritizes minimizing race conditions by raising as promptly as possible. The package has no runtime dependencies and is built for modern Python versions (3.9–3.13). It draws inspiration from async_timeout and cpython's asyncio.timeout, making it a focused alternative for scenarios where you need fine-grained control over future-based interruption. With active maintenance and a permissive Apache-2.0 license, it is production-ready for integration into async workflows. Use it for: - Cancel long-running async operations when an external signal (represented as a future) fires. - Implement custom timeout or deadline logic by raising an exception tied to a future's completion. - Coordinate async task interruption across multiple coroutines without race conditions. - Build async state machines that respond to external events by raising controlled exceptions. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides an asyncio context manager that interrupts a block of code and raises an exception when a future completes, designed to minimize race conditions. Yes. The package is lightweight, actively maintained, has no dependencies, supports current Python versions, carries no known vulnerabilities, and solves a specific asyncio coordination problem with a permissive license. Install it if you need future-based interruption with minimal race-condition risk. ## Install pip install async-interrupt uv add async-interrupt poetry add async-interrupt ## Installing async-interrupt Before you install: Low install friction with no runtime dependencies. Actively maintained with a recent release (2025-02-22) and ongoing repository activity. Supports Python 3.9 through 3.13. License in practice: Licensed under Apache-2.0 (permissive), allowing free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects. Quickstart: pip install async_interrupt import asyncio from async_interrupt import interrupt async def example(): future = asyncio.Future() async with interrupt(future, ValueError, "message"): future.set_result(None) await asyncio.sleep(0) Requires Python 3.9 or later. Verify before relying: - Whether the package handles edge cases like nested interrupts or multiple concurrent futures. - Performance characteristics when used with high-frequency future completions. - Detailed comparison to cpython asyncio.timeout behavior and when to choose one over the other. ## Package facts - License: Apache-2.0 (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 907.8K/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags asyncio interrupt context manager, async future exception raising, asyncio timeout alternative, interrupt async code block, future completion handler, asyncio race condition prevention, async exception on future done, asyncio, context-manager, concurrency [View on SkillFed](https://skillfed.io/packages/async-interrupt) · [View on PyPI](https://pypi.org/project/async-interrupt/)