A decorator to call a function every n seconds
pip install adbescapes repeatdecorator
import time
from random import choice, uniform
from repeatdecorator import repeat_func, repeatdec_vars
@repeat_func(
repeat_time=0.1,
variablename="represults",
activate_lock=True,
ignore_exceptions=True,
exception_value="EXCEPTION",
max_len_allresults=None,
print_results=False,
print_exceptions=True,
execution_limit=20,
max_concurrent_threads=10,
check_max_threads_every_n_seconds=0.015,
)
def ha():
vall = choice([0, 1, 2])
time.sleep(uniform(.2, 1))
print(f'Running threads: {repeatdec_vars.active()} ')
return 5 / vall
print(f'START: Running threads: {repeatdec_vars.active()} ')
ha()
while not hasattr(repeatdec_vars, "represults"):
continue
for r in range(15):
print(f"{repeatdec_vars.represults=}")
time.sleep(0.5)
if r == 5:
repeatdec_vars.represults["enabled"] = False
break
#OUTPUT:
START: Running threads: 4
Running threads: 10
division by zero
repeatdec_vars.represults={'results': ['EXCEPTION'], 'enabled': True, 'total_count': 6}
repeatdec_vars.represults={'results': ['EXCEPTION'], 'enabled': True, 'total_count': 6}
Running threads: 10
repeatdec_vars.represults={'results': ['EXCEPTION', 5.0], 'enabled': True, 'total_count': 7}
Running threads: 10
repeatdec_vars.represults={'results': ['EXCEPTION', 5.0, 5.0], 'enabled': True, 'total_count': 8}
Running threads: 10
division by zero
repeatdec_vars.represults={'results': ['EXCEPTION', 5.0, 5.0, 'EXCEPTION'], 'enabled': True, 'total_count': 9}
Running threads: 10
repeatdec_vars.represults={'results': ['EXCEPTION', 5.0, 5.0, 'EXCEPTION', 2.5], 'enabled': True, 'total_count': 10}
Running threads: 10
division by zero
Running threads: 9
Running threads: 8
Running threads: 7
division by zero
Running threads: 6
Running threads: 5
#Summary of repeat_func
Args:
f_py (Any)
Description Don't use - reserved for the function
Default None
repeat_time (Union[float,int])
Description Execute each n seconds
Default 1.0
variablename (str)
Description Creates a dict for the results in repeatdec_vars - Use repeatdecorator.repeatdec_vars.variablename to access it
Default "threadresults"
activate_lock (bool)
Description Threading Rlock
Default False
ignore_exceptions (bool)
Description Continue on Exceptions?
Default False
exception_value (Any)
Description Ignored if ignore_exceptions is False
Default None
max_len_allresults (Union[int,None])
Description If None, results are stored in a list (no limit), if int, a deque is used to store
the results. Results can be found here: repeatdecorator.repeatdec_vars.variablename["results"]
Make sure to save the results before calling the function again.
Default None
print_results (bool)
Description Print the return value from each function?
Default True
print_exceptions (bool)
Description Print Exceptions
Default True
execution_limit (int)
Description Stop timer after n executions / -1 = No limit
Default -1
max_concurrent_threads (int)
Description Thread limit / -1 = No limit
Default -1
check_max_threads_every_n_seconds (Union[float,int])
Description Sleep time before checking the current number of threads again.
Default 0.015
Returns:
Any: Description of return value
Metadata
Release files for repeatdecorator 0.10
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 |
|---|---|---|---|---|
| repeatdecorator-0.10.tar.gz | 4.8 kB | Without provenance | Details for repeatdecorator-0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| repeatdecorator-0.10-py3-none-any.whl | Python 3 | none | any | Details for repeatdecorator-0.10-py3-none-any.whl |
Total release size: 11.3 kB
Release files / repeatdecorator-0.10.tar.gz
| Download URL | repeatdecorator-0.10.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89a5fd31208325790a16be68c2120dedd519511250ba2113c332d7a5c6eecf1c
|
|
BLAKE2b-256 checksum How to use checksums |
eda197e4c2beefd99518e50bf4b604acda53905019013528ef4897899767aea8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / repeatdecorator-0.10-py3-none-any.whl
| Download URL | repeatdecorator-0.10-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b24eb2ba3ef07051d2deea710767909d371bd01f66c2cb65bf1a1836e70b6ce9
|
|
BLAKE2b-256 checksum How to use checksums |
049d89c8cd1aeb8949047ce9215d877dbaa77c3dd2ec4a3e555e0b3841391100
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for repeatdecorator 0.10
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.