async-interrupt
Context manager to raise an exception when a future is done
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 on this page — 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
async-interrupt on PyPI
pip
pip install async-interruptuv
uv add async-interruptpoetry
poetry add async-interruptInstalling 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 the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 538 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 907,830/month — #4,756 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: async_interrupt-1.2.2-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
interruptingcowInterrupts long-running Python code by raising…
permissive · top 15,000 on PyPI
async-timeoutProvides an asyncio-compatible timeout context…
permissive · top 1,000 on PyPI
aiousbwatcherWatches for USB devices being plugged in and…
permissive · top 15,000 on PyPI
cysignalsProvides interrupt and signal handling…
copyleft · top 15,000 on PyPI
stopitProvides context managers and decorators to…
permissive · top 15,000 on PyPI
aiozoneinfoFetches timezone information asynchronously…
permissive · top 15,000 on PyPI
wait-for2Provides an alternate implementation of…
permissive · top 15,000 on PyPI
aiohappyeyeballsImplements Happy Eyeballs (RFC 8305) connection…
permissive · top 100 on PyPI
taskgroupBackports asyncio.TaskGroup, asyncio.Runner,…
permissive · top 5,000 on PyPI
jaraco.contextProvides decorators and context managers for…
permissive · top 1,000 on PyPI