timework
A package used to set time limits.
Install
pip install timework
Usage
import timework as tw
timework.timer
import logging
@tw.timer(logging.warning)
def timer_demo_a():
i = 0
while i < 2 ** 23:
i += 1
return i
@tw.timer(print, detail=True)
def timer_demo_b():
i = 0
while i < 2 ** 24:
i += 1
return i
@tw.timer(timeout=1)
def timer_demo_c():
i = 0
while i < 2 ** 25:
i += 1
return i
a = timer_demo_a()
b = timer_demo_b()
try:
c = timer_demo_c()
except tw.TimeError as e:
print('error:', e.message)
c = e.result
print(a, b, c)
WARNING:root:timer_demo_a: 0.496672 seconds used
START: Tue Feb 18 15:06:45 2020
FINISH: Tue Feb 18 15:06:46 2020
timer_demo_b: 0.989352 seconds used
error: timer_demo_c: 1.9817 seconds used
8388608 16777216 33554432
timework.limit
@tw.limit(3)
def limit_demo(m):
i = 0
while i < 2 ** m:
i += 1
return i
try:
s = limit_demo(4)
except tw.TimeError as e:
print(e)
else:
print('result:', s)
try:
s = limit_demo(30)
except tw.TimeError as e:
print(e)
else:
print('result:', s)
result: 16
limit_demo: 3 seconds exceeded
timework.iterative
@tw.iterative(3)
def iterative_demo_a(max_depth):
i = 0
while i < 2 ** max_depth:
i += 1
return max_depth, i
@tw.iterative(3, history=5, key='depth')
def iterative_demo_b(depth):
i = 0
while i < 2 ** depth:
i += 1
return depth
try:
s = iterative_demo_a(max_depth=10)
except tw.TimeError as e:
print(e.message)
print(e.result, e.detail)
else:
print('result:', s)
try:
s = iterative_demo_a(max_depth=25)
except tw.TimeError as e:
print(e.message)
print(e.result, e.detail)
else:
print('result:', s)
try:
s = iterative_demo_b(depth=25)
except tw.TimeError as e:
print(e.message)
print(e.result, e.detail)
else:
print('result:', s)
result: (10, 1024)
iterative_demo_a/iterative_deepening: 3 seconds exceeded
(20, 1048576) deque([(20, 1048576)], maxlen=1)
iterative_demo_b/iterative_deepening: 3 seconds exceeded
20 deque([16, 17, 18, 19, 20], maxlen=5)
License
MIT 漏 bugstop
Metadata
Release files for timework 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| timework-0.2.0.tar.gz | 3.5 kB | Without provenance | Details for timework-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| timework-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for timework-0.2.0-py3-none-any.whl |
Total release size: 8.3 kB
Release files / timework-0.2.0.tar.gz
| Download URL | timework-0.2.0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b849d0b1c8f7c1c1ad5447b3f8471fa96b040d83a94deeeca4a525a17d697ca8
|
|
BLAKE2b-256 checksum How to use checksums |
b23562b7ac0b4ae8513ff19b84014736c2acc3ab5cfa0be05692793e203b8759
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.4
|
Release files / timework-0.2.0-py3-none-any.whl
| Download URL | timework-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2401f71bbcb345d66909041968c5b84ea0b3376fe9d2e4241f845e4bdea1b587
|
|
BLAKE2b-256 checksum How to use checksums |
d1d57358df37f0b0fc5044094ef27344a71f2b106a1f647e20ac4bee4600b087
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.4
|
Security for timework 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.