Skip to main content

It lets call any function with a timeout

Project description

pythonversions License

Timekiller

It lets call any function with a timeout!

Note: It works in main thread and processes (not work in threads)

Install

pip install timekiller

Link pypi: https://pypi.python.org/pypi/timekiller

Example

Call function

import timekiller
import time


def long_function(foo, bar):
    while True:
        time.sleep(10)
        print(foo, bar)

# call(func, max_time, *args, **kwargs)
timekiller.call(long_function, 5, "woo", bar="Uhmm")


@timekiller.timeout(5)
def long_function_with_decorator(foo, bar)
    while True:
        time.sleep(10)
        print(foo, bar)

long_function_with_decorator("woo", "Uhmm")

Capture exception

import timekiller
import time


@timeout(1)
def long_function():
    try:
        time.sleep(10)
    except timekiller.TimeoutException:
        print("capture exception")

long_function()

CHANGELOG

0.0.1 (2016-06-14)

  • Initial version

Project details


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