Skip to main content

A package used to set time limits.

Project description

timework

PyPI python Build Status Coverage Status codebeat badge

A package used to set time limits.

Install

pip install timework

Usage

import timework as tw
import logging

r = tw.ResultHandler(5)

@tw.timer(r)
def timer_demo_a():
    i = 0
    while i < 2 ** 23:
        i += 1
    return i

@tw.timer(r, out=print)
def timer_demo_b():
    i = 0
    while i < 2 ** 24:
        i += 1
    return i

@tw.timer(r, out=logging.warning)
def timer_demo_c():
    i = 0
    while i < 2 ** 25:
        i += 1
    return i

@tw.limit(3)
def limit_demo(m):
    i = 0
    while i < 2 ** m:
        i += 1
    return i

@tw.iterative(r, 1)
def iterative_demo(max_depth):
    i = 0
    while i < 2 ** max_depth:
        i += 1
    return max_depth, i


timer_demo_a()
timer_demo_b()
timer_demo_c()
print(r.value, end='\n\n')

try:
    s = limit_demo(4)
except Exception as e:
    print(e, end='\n\n')
else:
    print(s)

try:
    s = limit_demo(30)
except Exception as e:
    print(e, end='\n\n')
else:
    print(s)

try:
    r.clean()
    iterative_demo(max_depth=10)
except Exception as e:
    print(e)
finally:
    print(r.value, end='\n\n')

try:
    r.clean()
    iterative_demo(max_depth=25)
except Exception as e:
    print(e)
finally:
    print(r.value, end='\n\n')
timer_demo_b: 0.991348 seconds used
WARNING:root:timer_demo_c: 1.96977 seconds used
deque([0.5051665306091309, 0.9913477897644043, 1.96976900100708], maxlen=5)

16
limit_demo: 3 seconds exceeded

deque([(6, 64), (7, 128), (8, 256), (9, 512), (10, 1024)], maxlen=5)

iterative_deepening: 1 seconds exceeded
deque([(15, 32768), (16, 65536), (17, 131072), (18, 262144), (19, 524288)], maxlen=5)


Process finished with exit code 0

License

MIT 漏 bugstop

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

timework-0.1.1.tar.gz (3.1 kB view hashes)

Uploaded source

Built Distribution

timework-0.1.1-py3-none-any.whl (4.5 kB view hashes)

Uploaded py3

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