skillfed

stopit

Timeout control decorator and context managers, raise any exception in another thread

stopit v1.1.2 233.1K downloads/30d#9,046 on PyPI
Permissive license GPLv3 Abandoned released

What it is and what it does

stopit provides two main mechanisms for controlling execution time in Python: context managers and decorators that enforce timeouts on code blocks and function calls. The core capability is raising asynchronous exceptions in other threads, including the main thread, to interrupt long-running operations. It offers ThreadingTimeout (a context manager) and threading_timeoutable (a decorator) for timeout control, plus async_raise for direct thread interruption. The package also provides a TimeoutException that signals when a timeout has occurred.

The package is tightly coupled to CPython's threading implementation and uses low-level APIs that are not available on alternative Python implementations. It has important limitations: it cannot interrupt blocking Python atomic instructions that hold the GIL (such as time.sleep), and signal-based timeout controls do not work on Windows. The package is no longer maintained, with its last release in 2018-02-09.

Use it for:

  • Enforce maximum execution time on web request handlers or API calls that might hang indefinitely.
  • Interrupt long-running computations or data processing tasks if they exceed a time budget.
  • Implement watchdog timers for background worker threads that may become stuck.
  • Decorate functions to return a default value if they do not complete within a specified timeout.
  • Control timeout behavior in test suites to fail tests that run longer than expected.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides context managers and decorators to enforce timeouts on code blocks and function calls, and raise exceptions asynchronously in other threads.

No. The package is abandoned (last release 2018-02-09) with no maintenance signal. It relies on CPython-specific internals, does not work on alternative implementations, and has known limitations with GIL-blocking operations and Windows compatibility. For modern Python projects, consider maintained alternatives or the standard library's asyncio timeout mechanisms.

Install

stopit on PyPI

pip

pip install stopit

uv

uv add stopit

poetry

poetry add stopit

Installing stopit

Before you install

High install friction: the package is abandoned (last release 2018-02-09, 3108 days ago) and has no runtime dependencies. Threading-based timeout control relies on CPython-specific low-level APIs and will not work on alternative Python implementations (Jython, PyPy, IronPython). Signal-based timeouts do not work on Windows.

License in practice

Licensed under GPLv3 (permissive treatment noted), which permits use but requires derivative works to be distributed under the same license if distributed at all.

Quickstart

import stopit

with stopit.ThreadingTimeout(10) as to_ctx_mgr:
    # code that may take too long
    pass

if to_ctx_mgr.state == to_ctx_mgr.EXECUTED:
    print('Completed within timeout')

Requires CPython; will not work on Jython, PyPy, or IronPython. Signal-based timeout control unavailable on Windows.

Verify before relying

  • Whether the package works reliably on Python versions beyond 3.6 despite classifiers listing only up to 3.6.
  • Current status of any known issues with GIL-blocking operations beyond the documented time.sleep() limitation.
  • Whether the abandoned status poses compatibility or security risks for new projects.

Package facts

License GPLv3 (permissive)
Python support not specified
Install friction high — source build required
Runtime dependencies none
Maintenance abandoned — 3,108 days since the last release
First released
Downloads 233,110/month — #9,046 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: stopit-1.1.2.tar.gz

Keywords: threads, timeout

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2.6Programming Language :: Python :: 2.7Programming Language :: Python :: 3.3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: Implementation :: CPythonTopic :: Utilities

Tags

timeout context managerthread timeout controlasync exception in threadfunction timeout decoratorstop long-running codethreading timeoutinterrupt thread execution
threadingtimeout-controlabandoned

More Utilities packages