func-timeout
Python module which allows you to specify timeouts when calling any existing function. Also provides support for stoppable-threads
What it is and what it does
func_timeout wraps function calls in a timeout mechanism by running them in a separate thread and raising FunctionTimedOut if execution exceeds a specified duration. It returns the function's result or re-raises any exception it would normally throw. The package also includes a decorator form (@func_set_timeout) for cleaner syntax and a StoppableThread class that extends threading.Thread to support forceful termination via exception injection into the thread context.
The core use case is protecting against indefinite hangs in code you call but cannot control—network requests, file I/O, or third-party library calls that may block. Timeouts can be fixed values or computed dynamically based on function arguments. The FunctionTimedOut exception includes a retry() method to re-attempt the call with different timeout settings.
Use it for:
- Wrap external API calls or network requests to prevent indefinite blocking when servers hang or are unresponsive.
- Enforce maximum execution time on user-submitted or untrusted code in a sandbox or job queue.
- Decorate long-running data processing functions to fail fast if they exceed expected runtime.
- Implement graceful shutdown of worker threads in an event loop or thread pool by stopping them with a custom exception.
- Protect against infinite loops or deadlocks in third-party library code by terminating after a timeout.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Runs any Python function with a specified timeout limit, raising an exception if execution exceeds the time window; also provides a stoppable thread class for controlled thread termination.
Yes, with conditions. Install if you need timeout protection for function calls and can accept dormant maintenance (last release 2019). The package is stable, has no known vulnerabilities, and solves a real problem with minimal dependencies. Avoid if you require active support or need guaranteed compatibility with Python versions beyond 3.7, or if you prefer a maintained alternative. High install friction (source-only) is a minor friction point.
Install
func-timeout on PyPI
pip
pip install func-timeoutuv
uv add func-timeoutpoetry
poetry add func-timeoutInstalling func-timeout
Before you install
High install friction due to source-only distribution (tar.gz). Maintenance is dormant—last release was 2019-08-19, over six years ago, though the repository remains active with recent commits. Production-stable status and no known vulnerabilities suggest the code is stable, but no active development or support.
License in practice
Licensed under LGPLv2 (copyleft). Any derivative work or modification must be released under the same license; linking in a proprietary application requires careful review of your license obligations.
Quickstart
from func_timeout import func_timeout, FunctionTimedOut
try:
result = func_timeout(5, my_function, args=('arg1', 'arg2'))
except FunctionTimedOut:
print('Function exceeded 5 second timeout')
Requires Python 2.7 or 3.4+; uses threading and may have platform-specific behavior around exception injection into C code.
Verify before relying
- Whether the package works reliably on modern Python versions (3.8+) despite classifiers only listing up to 3.7.
- Performance impact of the polling mechanism (raises exception every 2 seconds) on CPU-bound workloads.
- Behavior when timing out functions that hold locks or interact with external resources.
Package facts
| License | LGPLv2 (copyleft) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | dormant — 2,552 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 7,584,368/month — #1,719 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: func_timeout-4.3.5.tar.gz
Keywords: function, timeout, call, terminate, runtime, max, seconds, after, execution
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
kthreadKThread provides a way to forcefully terminate…
permissive · top 15,000 on PyPI
stopitProvides context managers and decorators to…
permissive · top 15,000 on PyPI
timeout-samplerPolls a function repeatedly within a timeout…
permissive · top 15,000 on PyPI
threadedProvides decorators to wrap functions for…
permissive · top 15,000 on PyPI
timeout-decoratorA decorator that enforces time limits on…
permissive · top 5,000 on PyPI
retry2Provides a decorator and function wrapper to…
permissive · top 5,000 on PyPI
pytest-timeoutAborts pytest tests that exceed a specified…
permissive · top 1,000 on PyPI
retryProvides a decorator and function wrapper for…
permissive · top 1,000 on PyPI
async-timeoutProvides an asyncio-compatible timeout context…
permissive · top 1,000 on PyPI
python-backoffProvides function decorators for retrying…
permissive · top 5,000 on PyPI