skillfed

async-interrupt

Context manager to raise an exception when a future is done

async-interrupt v1.2.2 907.8K downloads/30d#4,756 on PyPI2
Permissive license Apache-2.0 Active released

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-interrupt

uv

uv add async-interrupt

poetry

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 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries

Tags

asyncio interrupt context managerasync future exception raisingasyncio timeout alternativeinterrupt async code blockfuture completion handlerasyncio race condition preventionasync exception on future done
asynciocontext-managerconcurrency

More Libraries packages