Timeloop-NG
Timeloop-NG (for next generation) is a service that can be used to run periodic tasks after a certain interval.
It's the successor of timeloop from Sankalp Jonna as pull requests were never accepted.
Each job runs on a separate thread and when the service is shut down, it waits till all tasks currently being executed are completed.
Installation
pip install timeloop-ng
Writing jobs
The jobs run the first time after the first wait interval.
import time
from timeloop import Timeloop
from datetime import timedelta
tl = Timeloop()
@tl.job(interval=timedelta(seconds=2))
def sample_job_every_2s():
print("2s job current time : {}".format(time.ctime()))
@tl.job(interval=timedelta(seconds=5))
def sample_job_every_5s():
print("5s job current time : {}".format(time.ctime()))
@tl.job(interval=timedelta(seconds=10))
def sample_job_every_10s():
print("10s job current time : {}".format(time.ctime()))
Jobs that only run a certain amount of time
By default, all jobs run until they are stopped. At times you may want to run a job only once or twice.
import time
from timeloop import Timeloop
from datetime import timedelta
tl = Timeloop()
@tl.job(interval=timedelta(seconds=10), num_executions=2)
def run_me_twice_with_10s_pause():
print("10s job current time : {}".format(time.ctime()))
Jobs with a different initial interval
At times, you want
@tl.job(interval=timedelta(seconds=1), initial_delay=timedelta(seconds=10))
def run_after10s_and_then_every_second():
print("job current time : {}".format(time.ctime()))
@tl.job(interval=timedelta(seconds=1), num_executions=2, initial_delay=timedelta(seconds=10))
def run_after10s_and_then_after_1second_then_stop():
print("job current time : {}".format(time.ctime()))
Start time loop in separate thread
By default timeloop starts in a separate thread.
Please do not forget to call tl.stop before exiting the program, Or else the jobs wont shut down gracefully.
tl.start()
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
tl.stop()
break
Start time loop in main thread
Doing this will automatically shut down the jobs gracefully when the program is killed, so no need to call tl.stop
tl.start(block=True)
Author
- Sankalp Jonna (author of the original version)
- Christoph Becker aka tuergeist
Metadata
Release files for timeloop-ng 1.0.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 | |
|---|---|---|---|---|
| timeloop-ng-1.0.0.tar.gz | 4.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| timeloop_ng-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.4 kB
Release files / timeloop-ng-1.0.0.tar.gz
| Download URL | timeloop-ng-1.0.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2fd07e2aa852ab3402b0243aaabfa4993bd50ab0ecbdd92567d8ec301b666022
|
|
BLAKE2b-256 checksum How to use checksums |
31385a30ca30074eb5a110c3aadf6e399120287223865cf45f4e58777cf303d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|
Release files / timeloop_ng-1.0.0-py3-none-any.whl
| Download URL | timeloop_ng-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d8349b3212ef96a53de7c3568c61ae6e186206263c9408db143fd35607d47cf
|
|
BLAKE2b-256 checksum How to use checksums |
c698064e18f6cda5f7cd62286a15126fc154701b6d42cc6a5e2ea943360c3254
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|
Security for timeloop-ng 1.0.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.