skillfed

func-timeout

Python module which allows you to specify timeouts when calling any existing function. Also provides support for stoppable-threads

func-timeout v4.3.5 7.6M downloads/30d#1,719 on PyPI328
Copyleft license LGPLv2 DORMANT released

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

uv

uv add func-timeout

poetry

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

Development Status :: 5 - Production/StableLicense :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)Programming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Topic :: Software Development :: Libraries :: Python Modules

Tags

function timeout decoratorcall function with timeoutterminate long-running functionstoppable threads pythonexecution time limitfunction execution timeoutthread stop exception
thread-controlexecution-limits

More Python Modules packages