Skip to main content

Process based timeout context decorator

Project description

py-timeout

Actions Status PyPI - Status PyPI - Python Version PyPI PyPI - License


py-timeout - pure Python process based decorator that provides execution timeout for Python functions and methods. Since it is not based on signals, py-timeout works fine outside the main thread.

Prerequisites

py-timeout requires python 3.6 or newer versions to run.

Installing

Cloning project from git repository

git clone https://github.com/YADRO-KNS/py-timeout.git

Installing from PyPi

pip3 install py-timeout

Examples

import timeout

@timeout.timeout(duration=0.5)
def foo(value: int) -> None:
    ...

...

@timeout.timeout(duration=0.5)
def bar(self, value: str) -> str:
    ...

Decorated function or method will be executed as a sub-process with expected life-time of passed duration value.

import timeout
import time

@timeout.timeout(duration=5)
def foo() -> None:
    while True:
        time.sleep(1)

try:
    foo()
except timeout.TimeoutException:
    pass

In case if for some reason execution will take longer than expected the process will be terminated and TimeoutException will be raised.

Versioning

We use SemVer for versioning.

Authors

See also the list of contributors who participated in this project.

License

The code is available as open source under the terms of the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-timeout-0.0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

py_timeout-0.0.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file py-timeout-0.0.1.tar.gz.

File metadata

  • Download URL: py-timeout-0.0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8

File hashes

Hashes for py-timeout-0.0.1.tar.gz
Algorithm Hash digest
SHA256 819f5d5ed1b320dd2f5cb5f01a623b8bead9231be9aa16aad193fcb4ca27bc27
MD5 b4e66c92bc2d128ed531cb550a29cdc8
BLAKE2b-256 1cbed6f0886519d05256668b9c1971509996700543857e0334f5dcbd39c2c92b

See more details on using hashes here.

File details

Details for the file py_timeout-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: py_timeout-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8

File hashes

Hashes for py_timeout-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c3c14b81d242e8d5ac8e8cb945c349ef2b26b4586e9f132cb744eec9ad04f521
MD5 e976d562e82971662f262d8a89856462
BLAKE2b-256 60263ec50d61f9b84105279cdbc80a20bfb94d566362f60c0dac5921cd396448

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page