Skip to main content

add timeout to any function

Project description

ktimeout

python_version PyPI downloads/month

Description

add timeout to any function

Install

pip install ktimeout
# or
pip3 install ktimeout

Usage

# CHECK 'demo.py' FOR ALL EXAMPLES
from typing import Optional
import time

from ktimeout import timeout

def func_with_arguments(sleep_time: float, extra_print: Optional[str] = None):
    while True:
        time.sleep(sleep_time)

        print('Sleeping', sleep_time, 'sec', extra_print or '')

def func():
    func_with_arguments(0.5, extra_print='called from func()')

try:
    timeout.run(func, 2)
except Exception as e:
    print(e)

try:
    timeout.run(
        timeout.partial(func_with_arguments, 0.25, extra_print='extra'),
        2
    )
except Exception as e:
    print(e)

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

ktimeout-0.0.6.tar.gz (2.0 kB view hashes)

Uploaded Source

Built Distribution

ktimeout-0.0.6-py3-none-any.whl (3.2 kB view hashes)

Uploaded Python 3

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