--- id: func-timeout version: "4.3.5" license: LGPLv2 license_treatment: copyleft maintenance: dormant --- # func-timeout — Python module which allows you to specify timeouts when calling any existing function. Also provides support for stoppable-threads License: copyleft · Maintenance: dormant · Downloads: 7.6M/mo ## 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 above — 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 pip install func-timeout uv add func-timeout poetry add func-timeout ## Installing 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: unspecified - Install friction: high - Maintenance: dormant - Downloads: 7.6M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags function timeout decorator, call function with timeout, terminate long-running function, stoppable threads python, execution time limit, function execution timeout, thread stop exception, thread-control, execution-limits [View on SkillFed](https://skillfed.io/packages/func-timeout) · [View on PyPI](https://pypi.org/project/func-timeout/)