Skip to content

YADRO-KNS/py-timeout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages