Skip to main content

timeout decorator for python

Project description

kth-timeoutdecorator

简介

kth-timeoutdecorator 是一个用于Python的超时修饰器,目前已在 Windows 和 Linux 下测试过,也经过了异步兼容的测试,目前只是基本实现了要达到的目的。

修改自这份 原代码 不过它无法正常使用。

Why

实际上超时修饰有很多,但大多数都有很多问题,一部分只能运行在 Linux 系统上,还有一部分无法异步兼容,使得无法满足我的另一个项目 XUN_Bot 的需求,直到我找到了这份 原代码,令人非常惊艳的code,但是由于部分原因使得它无法被正常使用。而本项目是我修改后可以正常使用的版本。

安装

From source code:

python setup.py install

From pypi:

pip install kth-timeoutdecorator

使用方法

import time
from kth_timeoutdecorator import *

@timeout(4)
def testmain():
    print("Start")
    for i in range(6):
        time.sleep(1)
        print("[Test] {} seconds have passed".format(i+1))

def mytest():
    try:
        testmain()
    except TimeoutException as e:
        print("[Test] {}".format(e))

if __name__ == '__main__':
    mytest()

如果执行成功,则会输出以下信息:

[Test] 1 seconds have passed
[Test] 2 seconds have passed
[Test] 3 seconds have passed
[Test] function run too long, time limit exceeded.

开源许可证

本项目使用 MIT 许可证。

开发日志

0.0.4

  • 修改了seconds参数的可选项,使得修饰器更加灵活。

0.0.5

  • 修复了之前版本的bug,请勿再使用0.0.2版本

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

kth-timeoutdecorator-0.0.5.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

kth_timeoutdecorator-0.0.5-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file kth-timeoutdecorator-0.0.5.tar.gz.

File metadata

  • Download URL: kth-timeoutdecorator-0.0.5.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for kth-timeoutdecorator-0.0.5.tar.gz
Algorithm Hash digest
SHA256 8b1e763232414c482fe8bc43c3678726a8fbacebd8d1e8e523579bacc4806858
MD5 1494f69f22ae560afce9638bdf88a956
BLAKE2b-256 67b3b37ff010f71cef0f199332c857dfd599922646a71c868479d3b021174141

See more details on using hashes here.

File details

Details for the file kth_timeoutdecorator-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: kth_timeoutdecorator-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for kth_timeoutdecorator-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5cf52acbdfb5606035d29b4e276876f73854f37ed076a266de8689225b4ea654
MD5 4a44fe053381f38bfe2c2d2a4e44d513
BLAKE2b-256 155f522a8cc5c92d747d40066da9362fe86d3188e1c80e7019454694ecd86345

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page