Single-thread interval scheduler
Project description
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_1
andtask_2
are defined using the@periodic
decorator with specified intervals.task_3
is scheduled withmake_periodic
, allowing custom parameters usingfunctools.partial
.run_loop
initiates 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.
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
Built Distribution
File details
Details for the file periodic_tasks-0.1.0.tar.gz
.
File metadata
- Download URL: periodic_tasks-0.1.0.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7f47415223958b720dfb4be9d6db82e44df0a64c6962ef1f8ca65780f1b7707 |
|
MD5 | dcc8cf1c9fee0b560020c9624f54ad76 |
|
BLAKE2b-256 | e6c184209ec657f80ef6513a29adb2b06cdc027d12b798375f92b96f726667a1 |
File details
Details for the file periodic_tasks-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: periodic_tasks-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c579073f5d584d8a8e7cfb975ffcbeab8c2cd40c274fdcacc8f27b5ce728e5d |
|
MD5 | 97c0551e6d2529ae96010a1c717f3e38 |
|
BLAKE2b-256 | 500a49662b93d86372b24662bb561b253fe93fc4d1140ae664d4526b1a8f3397 |