Skip to main content

Python Call function with timeouts

Project description

call_function_with_timeout

A library to make your funtions support timeouts

Example

import time
from call_function_with_timeout import SetTimeout

# make your function
def do_something(a=0, b=0):
    time.sleep(10)
    print(a + b)

# define function with timeout
func_with_timeout = SetTimeout(do_something, timeout=5)
# call the function
is_done, is_timeout, erro_message, results = func_with_timeout(a=12, b=8)

You will find that after the method is called to the time you specified, it will return and kill the currently executing thread.

You can also use it as a decorator

import time
from call_function_with_timeout import SetTimeoutDecorator

# make your function with timeout
@SetTimeoutDecorator(timeout=5)
def do_something(a=0, b=0):
    time.sleep(10)
    print(a + b)

# call the function
is_done, is_timeout, erro_message, results = do_something(a=12, b=8)

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

call_function_with_timeout-1.1.1.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

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