Skip to content

GlobalStudioES/timekiller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pythonversions License

Timekiller

It lets call any function with a timeout!

Install

pip install timekiller

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

Example

Call function

from timekiller import timeout, call
import time


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

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


@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

from timekiller import timeout, TimeoutException
import time


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

long_function()

TODO:

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

About

It lets call any function with a timeout!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages