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参数的可选项,使得修饰器更加灵活。

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.4.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

kth_timeoutdecorator-0.0.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kth-timeoutdecorator-0.0.4.tar.gz
  • Upload date:
  • Size: 3.4 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.4.tar.gz
Algorithm Hash digest
SHA256 bbf5f994c39eafc202229da95d0c59985bb5868a977bf046deabac7238a488cf
MD5 3023ca71fcacfe44f8fd389d48fda754
BLAKE2b-256 47d9f75d18d408931053140ec2b3847b0303505aa2f4a6fe88af579b6ae6f57f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kth_timeoutdecorator-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 86198e897f8831d8928098bc5598781ac7b77bf83b912421a77d4c768fafc5e2
MD5 b522fdd86b6ed935af5949da2d2db98e
BLAKE2b-256 0fed4ad0c2e344b2317a6ec086bfa33833979dce4156c522df3b2119955ff521

See more details on using hashes here.

Supported by

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