Periodic Task Scheduling Package Review
This package provides a lightweight framework for scheduling and executing periodic tasks with precision. Its minimalist syntax and focused functionality make it well-suited for business-critical applications that require reliable task execution at fixed intervals.
Key Features
- Minimalist Design: The package avoids unnecessary complexity, focusing on a clear and concise interface for defining and managing periodic tasks.
- No Busy-Waiting: It uses an efficient wait mechanism, minimizing CPU usage during idle periods between task executions.
- Missed Execution Handling: If a task misses its scheduled execution due to delays or processing overhead, the package tracks these missed executions without stacking them up, ensuring that the application stays responsive.
- Accurate Timing: Tasks are executed with a high degree of timing accuracy, crucial for applications with strict timing requirements.
Example Usage
The following example demonstrates how to create periodic tasks using the package:
import time
from datetime import timedelta
from functools import partial
from periodic_tasks import periodic, run_loop, make_periodic
start_time = time.time()
# Define a fast task that executes every 0.1 seconds
@periodic(interval=0.1)
def task_1():
dt = time.time() - start_time
print(f"Started a _fast_ task at t={{dt:.3f}}")
# Define a slower task that executes every 0.5 seconds
@periodic(interval=0.5)
def task_2():
dt = time.time() - start_time
print(f"Started a *slow* task at t={{dt:.3f}}")
if dt < 2:
time.sleep(0.91) # Simulate a delay in the task
else:
time.sleep(0.09) # Shorter delay after initial period
# Create a custom task with parameters
def task_3(custom_text: str):
print(custom_text)
time.sleep(0.5)
# Schedule task_3 to run periodically using a partial function
make_periodic(partial(task_3, "Hello periodic"), interval=timedelta(milliseconds=100))
# Start the periodic task loop
run_loop()
In this example:
task_1andtask_2are defined using the@periodicdecorator with specified intervals.task_3is scheduled withmake_periodic, allowing custom parameters usingfunctools.partial.run_loopinitiates the loop that manages the task execution, handling missed executions without delay accumulation.
Overall, this framework offers robust, no-frills functionality for time-sensitive applications, and its approach to task scheduling is both efficient and effective.
Metadata
Release files for periodic-tasks 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| periodic_tasks-0.1.2.tar.gz | 4.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| periodic_tasks-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.4 kB
Release files / periodic_tasks-0.1.2.tar.gz
| Download URL | periodic_tasks-0.1.2.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1c7b7e49f03a92dc8903611bc14f63199f0c6b83096fbeede2b1feaa618b7535
|
|
BLAKE2b-256 checksum How to use checksums |
c2d74fa8e57aebbf34bb6aee79a4c50984f22add793c95dddce5c13671a73be2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / periodic_tasks-0.1.2-py3-none-any.whl
| Download URL | periodic_tasks-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c1392193328f15436aca07fdb43a9a52e9b78533afa76ad1d4bdcc69810038b
|
|
BLAKE2b-256 checksum How to use checksums |
20b7f48caa0610b6437a5a190cfc25d47772b6b87eaa0605317a7019f40121ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|