Skip to main content

Limit the function execution time

This module provides a decorator which runs the function in a separate multiprocessing.Process and sends SIGKILL after the specified timeout if the function didn't complete.

Requirements

  • Python 3.7+ (needed for multiprocessing.Process.kill)

Install

pip install kill-timeout

Usage

from kill_timeout import kill_timeout


limit_in_seconds = 5


@kill_timeout(limit_in_seconds)
def long_running_function(**parameters):
    """Function which makes some computations

    It could take too long for some parameters.
    """
    ...

try:
    result = long_running_function(iterations=9001)
    print("Function returned: %r" % result)
except TimeoutError:
    print("Function didn't finished in %d seconds" % limit_in_seconds)
except Exception:
    print("Function failed with its internal error! Its original traceback:")
    raise

Metadata

Release files for kill-timeout 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kill-timeout 0.0.3
File Size Uploaded
kill_timeout-0.0.3.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kill-timeout 0.0.3
File Interpreter ABI Platform
kill_timeout-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 6.6 kB

Release files / kill_timeout-0.0.3.tar.gz

Download URL kill_timeout-0.0.3.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
03485a3a07ef00f5dd27b53fb4309cf0b22f8ca3a2b00aa3bf95b4a619878f4b
BLAKE2b-256 checksum
How to use checksums
18c104a4a45f0d33d2233c1b53f96392c95680ac5b7713abb744df0270306edc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

Release files / kill_timeout-0.0.3-py3-none-any.whl

Download URL kill_timeout-0.0.3-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bd2934c091f50cb397f7eddef9a4f95e12a1afc45f1ecdc32274d44fc263ba4
BLAKE2b-256 checksum
How to use checksums
792744f23715790c0c33a88063e751d9f2b7209fe74c394a747f4cc5d4a93a8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page