An elegant way to run period tasks.
Project description
# Timeloop
Timeloop is a service that can be used to run periodic tasks after a certain interval.

Each job runs on a separate thread and when the service is shut down, it waits till all tasks currently being executed are completed.
Inspired by this blog [`here`](https://www.g-loaded.eu/2016/11/24/how-to-terminate-running-python-threads-using-signals/)
## Installation
```sh
pip install timeloop
```
## Writing jobs
```python
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())
```
## 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.
```python
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```
```python
tl.start(block=True)
```
## Author
* **Sankalp Jonna**
Email me with any queries: [sankalpjonna@gmail.com](sankalpjonna@gmail.com).
Timeloop is a service that can be used to run periodic tasks after a certain interval.

Each job runs on a separate thread and when the service is shut down, it waits till all tasks currently being executed are completed.
Inspired by this blog [`here`](https://www.g-loaded.eu/2016/11/24/how-to-terminate-running-python-threads-using-signals/)
## Installation
```sh
pip install timeloop
```
## Writing jobs
```python
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())
```
## 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.
```python
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```
```python
tl.start(block=True)
```
## Author
* **Sankalp Jonna**
Email me with any queries: [sankalpjonna@gmail.com](sankalpjonna@gmail.com).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
timeloop-1.0.2.tar.gz
(2.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file timeloop-1.0.2.tar.gz.
File metadata
- Download URL: timeloop-1.0.2.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e716c67fe6bcadcee7ddb91e2520792426818a70f27e630cfbbbd9becc48a13
|
|
| MD5 |
791704da1f2e0494aa79229d999fd8cb
|
|
| BLAKE2b-256 |
6a953e39ee32f15a8e9dea46bb52300611a5351964eeaa393bafb0d738e90ce0
|
File details
Details for the file timeloop-1.0.2-py2-none-any.whl.
File metadata
- Download URL: timeloop-1.0.2-py2-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70cb69eeef39968ea0e6dd68a3a3a51257d5f4aa27b177ab1b19ca86ff525946
|
|
| MD5 |
a588891654e05ba9b8018dfc9b4d170f
|
|
| BLAKE2b-256 |
ade7371d64fc6c6fce53c490fc38816a77fe8c75ff608edc0807170ff3c62bf2
|