TimerThread
TimerThread is
- A lightweight task scheduling timer
- written in Python (3.7+) Standard Library
TimerThread supports to
- schedule task execution after a given delay
- schedule recurring task execution
- run in the background
- use
@taskdecorator to define task
Quickstart
Define your function, now(cost) as an example:
import time
def now(cost=1):
time.sleep(cost)
print( time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime()) )
Create a TimerThread scheduler and start it:
import timerthread
timer = timerthread.Scheduler('recur', 3, now, args=(1,))
timer.start()
Shutdown the scheduler:
timer.cancel()
Play with the @task decorator
Use @task decorator to define your function, then schedule it and start the scheduler, now(cost) as an example:
import time
import timerthread
@timerthread.task('recur', 3)
def now(cost=1):
time.sleep(cost)
print( time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime()) )
timer = now.sched(cost=1)
timer.start()
When you'd like to cancel the recurring execution, shutdown the scheduler as usual:
timer.cancel()
Install TimerThread
$ pip install timerthread
Documentation
Scheduler
class timerthread.Scheduler(trigger, interval, fn, args=(), kwargs={})
trigger must be 'delay' or 'recur'.
-
stoppedThe scheduler is stopped or not,
True(default) orFalse. -
resultThe execution result,
{}as default. -
start()Let scheduler start executing your function as scheduled in the background.
-
cancel()Shutdown the scheduler.
task
class timerthread.task(trigger, interval)
trigger must be 'delay' or 'recur'.
-
Use
@taskdecorator to define your function, then schedule it and start the scheduler:@timerthread.task(trigger, interval) def fn(args, kwargs): pass timer = fn.sched(*args, **kwargs)
fn.sched(*args, **kwargs)returnstimerthread.Schedulerinstance.
Related Projects
Metadata
Release files for TimerThread 0.1.1
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 |
|---|---|---|---|---|
| TimerThread-0.1.1.tar.gz | 3.1 kB | Without provenance | Details for TimerThread-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| TimerThread-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for TimerThread-0.1.1-py3-none-any.whl |
Total release size: 7.5 kB
Release files / TimerThread-0.1.1.tar.gz
| Download URL | TimerThread-0.1.1.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
417ee7c80ecefc25e7e74759d0d69b4f2b63bb351fb39fa5c362e529b4efdbc6
|
|
BLAKE2b-256 checksum How to use checksums |
9e2473de674f0324c62952d8662b7affc42e4a9a40e36921661875b121a2b723
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
|
Release files / TimerThread-0.1.1-py3-none-any.whl
| Download URL | TimerThread-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd819676f758933440f60207379f6dc1421856ffc34888fe18269edcd6a2cd92
|
|
BLAKE2b-256 checksum How to use checksums |
125269a4d2d446a72feaaa4488c9b71269d51bc17939a9d43922d85a6dd57ef1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
|
Security for TimerThread 0.1.1
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.