A simple Python task scheduler that supports daily tasks with additional performance benefits due to the use of thread sleeping.
target: The function or method to be executed by the task.*args: Arguments to be passed to the target function.
Parses the input date and returns a datetime object.
Executes the task by calling the target function with the provided arguments.
Run a daily task starting from a specified date.
start_date(str | datetime): The starting date for the daily task. It can be a string in a recognizable format or a datetime object.recur_every(int): Number of days between each iteration. Default is 1.
Initializes a task scheduler.
Creates a new task and adds it to the scheduler.
target(Callable): The function or method to be executed by the task.*args(Any): Arguments to be passed to the target function.
Runs all tasks in the scheduler.
from taskscheduler import TaskScheduler
def daily_task():
print("This task runs daily!")
# Create a task scheduler
scheduler = TaskScheduler()
scheduler.create(daily_task)
# Schedule a daily task (automatically triggered, no manual execution needed)
daily_task = scheduler.daily(daily_task, recur_every=1)
## Notes
- Currently, only daily tasks are supported.
- The implementation utilizes thread sleeping for improved performance during task scheduling.
## Contribution
Contributions are welcome! Feel free to open issues or submit pull requests.