wrapt-timeout-decorator
The better timout decorator
Decision gist · record as of 2026-08-14
Yes, if you need a robust timeout decorator that handles methods and classes correctly and works cross-platform. The package is actively maintained, has no known vulnerabilities, and low install friction. However, reserve it as a last resort after checking whether the libraries you're calling already offer native timeout support; the subprocess overhead on Windows and repeated invocations can be significant. Ensure your decorated function arguments are pickleable.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- On Windows, subprocess strategy is the only option (signals unavailable); on POSIX systems, signals cannot be used within subthreads.
- Requires Python 3.8.0 or newer.
- Objects passed to decorated functions must be pickleable (dill is used for serialization).
License · maintenance · safety
MIT (permissive) — MIT license is permissive with no restrictions on commercial or private use. You may use, modify, and distribute this package freely provided you include the license notice.
last release 2024-02-28 (898 days) · last repo commit 2026-04-24 · 164 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 2,198,074 downloads/mo, #3,216 on PyPI
Alternatives
Verify before relying
from wrapt_timeout_decorator import timeout
import time
@timeout(5)
def example():
time.sleep(10)
if __name__ == '__main__':
example()- Whether the package handles timeout exceptions consistently across all Python versions it claims to support (3.8–3.12, PyPy 3.9–3.10).
- Performance overhead of subprocess spawning on repeated decorator invocations in tight loops.
- Compatibility with async/await and asyncio event loops beyond the mentioned FastAPI/Uvicorn considerations.
What it is and what it does
wrapt_timeout_decorator is a decorator library that enforces time limits on function execution in Python. It addresses the common problem of functions that may hang indefinitely by wrapping them with a timeout mechanism. Unlike simpler timeout decorators, this package handles edge cases correctly: it works with class methods, static methods, instance methods, and preserves traceback information for debugging in tools like PyCharm.
The package offers two timeout strategies. On POSIX systems (Linux, macOS), it can use signals for elegant, efficient timeouts, but with caveats documented in the project. By default and on Windows, it uses subprocesses to enforce timeouts, which requires that decorated function arguments and return values be serializable via dill. The timeout value can be static, dynamically calculated, or adjusted via an optional eval function. It depends on wrapt, multiprocess, dill, psutil, and utility packages for subprocess management and test-environment detection.
Use it for
- Wrap database queries or network calls that may hang, ensuring they fail fast with a timeout exception rather than blocking indefinitely.
- Protect long-running file I/O or data processing operations in batch jobs, applying a timeout at the function level to prevent resource exhaustion.
- Enforce time limits on third-party library calls where the library itself offers no timeout parameter, as a last resort after exhausting built-in options.
- Handle Windows compatibility for timeout-protected code by automatically falling back to subprocess strategy when signals are unavailable.
- Debug hanging functions in PyCharm by preserving full traceback information through the timeout mechanism.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you need a robust timeout decorator that handles methods and classes correctly and works cross-platform.
The package is actively maintained, has no known vulnerabilities, and low install friction. However, reserve it as a last resort after checking whether the libraries you're calling already offer native timeout support; the subprocess overhead on Windows and repeated invocations can be significant. Ensure your decorated function arguments are pickleable.
Install
wrapt-timeout-decorator on PyPI
Before you install
Low friction install with a pure-Python wheel. Maintenance is active with recent commits and stable production status. Six runtime dependencies (wrapt, multiprocess, dill, psutil, lib-detect-testenv, cli-exit-tools) are all standard libraries or well-maintained packages, posing no unusual risk.
On Windows, subprocess strategy is the only option (signals unavailable); on POSIX systems, signals cannot be used within subthreads. Requires Python 3.8.0 or newer. Objects passed to decorated functions must be pickleable (dill is used for serialization).
License in practice
MIT license is permissive with no restrictions on commercial or private use. You may use, modify, and distribute this package freely provided you include the license notice.
Quickstart
from wrapt_timeout_decorator import timeout
import time
@timeout(5)
def example():
time.sleep(10)
if __name__ == '__main__':
example()
Verify before relying
- Whether the package handles timeout exceptions consistently across all Python versions it claims to support (3.8–3.12, PyPy 3.9–3.10).
- Performance overhead of subprocess spawning on repeated decorator invocations in tight loops.
- Compatibility with async/await and asyncio event loops beyond the mentioned FastAPI/Uvicorn considerations.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.8.0 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 6 packagescli-exit-toolslib-detect-testenvmultiprocesspsutilwraptdill |
| Maintenance | Actively maintained 898 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,198,074 / month, #3,216 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonTopic :: Software Development :: Libraries :: Python Modules |
Evidence: wrapt_timeout_decorator-1.5.1-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “timeout for methods and classes”
- wrapt-timeout-decoratorApplies timeout limits to Python functions and methods via decorator,…
- pytest-timeoutAborts pytest tests that exceed a specified time limit, with stack…
- byteplus-python-sdk-v2Python SDK for calling Byteplus APIs with built-in support for…
Give your agent the search over MCP, or paste the wish link into any chat.
More Python Modules packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
PyYAML parses and emits YAML 1.1 data format, enabling serialization and deserialization of configuration files and Python objects to and from human-readable YAML text.
Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.
Provides reusable metadata objects for use with PEP-593 `typing.Annotated` to express common constraints like bounds, collection sizes, and predicates on types.
Install it if you use or build libraries that need to express type constraints in a standardized, inspectable way—or if you want to annotate your own types with…
Provides runtime tools to inspect and introspect Python type annotations, enabling programmatic examination of type hints at execution time.
See also timeout-decorator · interruptingcow · cli-exit-tools · retry-decorator · stopit · pytest-timeout · EasyProcess · func-timeout · wrapt · pytest-timeouts