Calendar scheduler
Project description
Calendar Scheduler for Recurring Events
Features
- Executes an action function on a schedule.
- Thread-safe: events can be added and canceled from different threads.
- Supports intervals from milliseconds to years.
- Uses the standard
schedscheduler. - Timezone support.
- Syntax similar to
datetime. - Events can be added at any time: before or after the scheduler starts, and from any thread.
- No additional packages required.
Installation
Install via pip:
pip install calsched
Install via uv:
uv pip install calsched
Import
from calsched import CalendarScheduler
Creating the Scheduler
scheduler = CalendarScheduler()
Running the Scheduler
Start the scheduler using the run() method:
scheduler.run()
However, it will immediately exit if no events are scheduled. At least one event must be scheduled before starting.
Example that prints the current time every second:
import datetime
from calsched import CalendarScheduler
def print_time():
print(datetime.datetime.now())
scheduler = CalendarScheduler()
scheduler.enter_every_second_event(action=print_time)
scheduler.run()
In this case, run() blocks the thread in which it is called.
The action function is executed in the same thread as the run() method.
To allow adding events after the scheduler has started, you can add a placeholder event before calling run() to keep the scheduler active:
scheduler = CalendarScheduler()
stub_event = scheduler.enter_hourly_event(action=lambda: None)
scheduler.run()
You can stop run() by canceling the placeholder event:
scheduler.cancel(stub_event)
Example of running in a separate thread:
import datetime
import threading
from time import sleep
from calsched import CalendarScheduler
def print_time():
print(datetime.datetime.now())
scheduler = CalendarScheduler()
stub_event = scheduler.enter_hourly_event(action=lambda: None)
thread = threading.Thread(target=scheduler.run)
thread.start()
sleep(1.0)
event = scheduler.enter_every_second_event(action=print_time)
sleep(5.0)
scheduler.cancel(stub_event)
scheduler.cancel(event)
thread.join()
Project details
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
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 calsched-1.0.0.tar.gz.
File metadata
- Download URL: calsched-1.0.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5795ea8f8499c43adf5af23ea72429e19b7a3d326d732df9114430ac84d7f499
|
|
| MD5 |
c2d5b788beaf81c90a613a2d87e5921d
|
|
| BLAKE2b-256 |
673ecc7c36010cf9c4da86473f0be634057e1c96761e7975ba3c479c32f8dfe6
|
File details
Details for the file calsched-1.0.0-py3-none-any.whl.
File metadata
- Download URL: calsched-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5089bb0326454fc9647bb6e0df0532b3bd7010531e1c5a48622ce889693acb3f
|
|
| MD5 |
fd64bfaebd37a83ab207d96fd05b9045
|
|
| BLAKE2b-256 |
f71d59f789f358fa2d240a4cf8d86b77b95b21c1726c79d63372b16744f69eb5
|