Skip to main content

schedcore

Tests Python Version Linter: Ruff License: MIT

A lightweight, thread-safe, and zero-dependency concurrent task scheduling engine for Python.

schedcore allows you to schedule tasks to execute in the future, handle recurring tasks, and process them concurrently using a custom-built, lightweight thread pool—all without the overhead of heavy third-party libraries.

🚀 Features

  • Zero Dependencies: Built entirely using Python's standard library (threading, queue, time).
  • Custom Execution Engine: Uses a custom ThreadPool designed for absolute bare-metal performance.
  • Thread-Safe Architecture: Protected by condition variables and thread-safe queues to prevent race conditions and spurious wakeups.
  • Configurable error handling: uses callback function for error handling which can be supplied via set_error_handler()
  • Graceful Shutdown: Implements the "Poison Pill" pattern to ensure all background OS threads terminate cleanly without leaking memory.
  • Modern Python: Fully type-hinted and compatible with Python 3.10+.

🛠️ Installation

This project uses uv, you can easily set it up for local development.

  1. Clone the repository:

    git clone [https://github.com/ckalandk/scheduler.git](https://github.com/ckalandk/schedcore.git)
    cd schedcore
    
  2. Install the package in editable mode using uv:

    uv sync

📖 Quick Start

The following example, demonstrate how to start a scheduler, submit tasks and gracefully shut it down

import time
from schedcore import Scheduler, Task

# 1. Define your tasks
def greet(name: str):
    print(f"[{time.strftime('%X')}] Hello, {name}!")

def recurring_ping():
    print(f"[{time.strftime('%X')}] Ping...")

def raise_error():
    raise ValueError("Task raised and exception")

def error_handler(exception, task):
    print(f"Task: {task} didn't execute du to an exception: {exception}")

if __name__ == '__main__':
    scheduler = Scheduler(workers=4)
    scheduler.set_error_handler(error_hander)

    scheduler.start()

    print(f"[{time.strftime('%X')}] Scheduler started.")

    # Run this task once
    task_one = Task(interval=2, repeat=False, func=greet, name="Alice")
    scheduler.schedule(task_one)

    # Runs repeatedly, every 1.5 seconds
    task_two = Task(interval=1.5, repeat=True, func=recurring_ping)
    scheduler.schedule(task_two)

    # Use error handler to manage failed to execute task
    task_three = Task(interval=3, repeat=False, func=raise_error)
    scheduler.schedule(task_three)
    try:
        time.sleep(6)
    except KeyboardInterrupt:
        pass
    finally:
        # 5. Cleanly shut down all background threads
        print("Shutting down gracefully...")
        scheduler.request_stop()

🧠 Architecture Overview

This library is split into three core components:

  1. Task: A lightweight container that holds the target function, (stored internally in a functools.partial), and its timing requirements (timeout, repeat).

  2. ThreadPool: A custom-built worker pool utilizing queue.Queue. It bypasses the heavy machinery of concurrent.futures.ThreadPoolExecutor for fire-and-forget tasks, ensuring maximum throughput.

  3. Scheduler: The orchestrator. It uses a queue.PriorityQueue and a threading.Condition to precisely calculate time deltas and hand off tasks to the ThreadPool at the exact right microsecond.

🧪 Running Tests

To run the test suite:

uv run pytest -v

📄 License

MIT License. See LICENSE for more information.

Metadata

Release files for schedcore 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for schedcore 0.3.3
File Size Uploaded Provenance Actions
schedcore-0.3.3.tar.gz 5.1 kB Without provenance Details for schedcore-0.3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for schedcore 0.3.3
File Interpreter ABI Platform Actions
schedcore-0.3.3-py3-none-any.whl Python 3 none any Details for schedcore-0.3.3-py3-none-any.whl

Total release size: 11.8 kB

Release files / schedcore-0.3.3.tar.gz

Download URL schedcore-0.3.3.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f0dc0526d48597733373672448c253389e16e7003294cd5ee3811d2314b5fb0c
BLAKE2b-256 checksum
How to use checksums
50e116cf40b9651d19f7db4f265f84a8974fd21c59f4b9fb1628495cddd8c4f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / schedcore-0.3.3-py3-none-any.whl

Download URL schedcore-0.3.3-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ea29e042b0ce4d28a0a25c1d0a89295ea23b07ff23dd3d4043ef71dfced1ad2
BLAKE2b-256 checksum
How to use checksums
199555a8db0505280efe5f143f09a0f1d8586e998135b2d1a165cad77fc49e38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for schedcore 0.3.3

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.

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page