Skip to main content

Test Coverage Stable Version Pre-release Version PyPI - Python Version PyPI Downloads

Runtime Threading

A high-level task abstraction layer for Python — designed to make concurrency easier to reason about and structure.

🚀 Why this exists

Concurrency in Python is powerful, but quickly becomes difficult to manage as systems grow:

  • Coordination between tasks becomes complex
  • Threads, locks, and events introduce implicit behavior
  • Control flow becomes harder to follow
  • Simple parallel work evolves into orchestration problems

👉 The core challenge is not execution — it's coordination.

This project introduces a structured task abstraction that makes concurrent systems easier to design, understand, and evolve.

✨ Features

  • 🧵 High-level task abstraction over threading primitives
  • 🔗 Coordination between tasks, locks, and events
  • 📦 Built-in support for producer/consumer patterns
  • ⚡ Simplified parallel operations
  • 🔄 Continuation-based workflows
  • 🧠 Structured task orchestration

📦 Use cases

This library is particularly useful when building:

  • Data pipelines
  • Background processing systems
  • Job orchestration workflows
  • Event-driven architectures
  • Services with coordinated parallel workloads

👉 Especially valuable when concurrency becomes part of the system design — not just an implementation detail.

🧵 Core idea

Instead of working directly with low-level primitives such as threads or synchronization objects, this library introduces a Task abstraction as the central unit of execution.

A task:

  • Represents a complete unit of work
  • Has a well-defined lifecycle
  • Can be composed with other tasks
  • Provides consistent handling of success and failure

👉 This enables reasoning about concurrency at a higher level.

🔄 Composability & orchestration

One of the key goals of this project is to make concurrent workflows composable:

  • Multiple tasks can be coordinated as a group
  • Execution flow can be expressed declaratively
  • Dependencies between tasks become explicit

👉 This shifts concurrency from control flow complexity to structured orchestration.

📦 Producer / Consumer patterns

The library includes support for queue-based processing patterns:

  • Decouples producers from consumers
  • Enables scalable work distribution
  • Simplifies pipeline-style architectures

👉 A common building block in data and backend systems.

🏗 Design philosophy

This project is built on a few key principles:

1. Abstraction over primitives

Low-level threading constructs are powerful but difficult to scale in complexity.

2. Composability over ad-hoc concurrency

Tasks should be easy to combine, coordinate, and reuse.

3. Predictability over flexibility

Clear execution flow is prioritized over complex edge-case handling.

4. Developer experience

Concurrency should be understandable — not something developers avoid.

🔗 What this enables

By introducing structured task orchestration, this library allows you to:

  • Build clearer concurrent architectures
  • Reduce coordination complexity
  • Improve readability of parallel workflows
  • Make systems easier to debug and maintain

👉 Particularly useful in systems where concurrency is a core concern.

⚖️ Trade-offs

Focus ✅ Not a goal ❌
Task abstraction Full async framework replacement
Structured orchestration Fine-grained thread control
Composability Covering every concurrency edge case

👉 The goal is not to replace Python’s concurrency model — but to make it more usable in real-world systems.

🧠 Inspiration

Inspired by:

  • Task-based programming models (e.g. C# Task Parallel Library)
  • Real-world concurrency challenges in backend systems
  • The need for more structured abstractions in Python

🎯 When to use

Use this library if you:

  • Work with non-trivial concurrency
  • Need to coordinate multiple operations
  • Want clearer structure in parallel workflows
  • Prefer higher-level abstractions over low-level control

🚫 When not to use

This library may not be necessary if:

  • Your concurrency needs are very simple
  • Direct use of threading or async is sufficient
  • You require fine-grained control over execution primitives

Part of a broader focus on:

  • Runtime abstractions
  • Clean architecture
  • Developer tooling in Python

👉 https://github.com/apmadsen

🤝 Contributing

Feedback and contributions are welcome!

⚙️ Example

from runtime.threading import InterruptSignal, InterruptException
from runtime.threading.tasks import Task, ContinuationOptions

try:
     signal = InterruptSignal()
     i = 227
     m = 0.78

     def fn(task: Task[float], i: float, m: float) -> float:
          task.interrupt.raise_if_signaled()
          return i * m

     def fn_continue(task: Task[float], preceding_task: Task[float], m: float) -> float:
          return preceding_task.result * m

     task1 = Task.run(fn, i, m)
     task2 = task1.continue_with(ContinuationOptions.ON_COMPLETED_SUCCESSFULLY, fn_continue, m)

     result1 = task1.result # -> 177.06
     result2 = task2.result # -> 138.1068

     task3 = Task.create(interrupt = signal.interrupt, lazy = True).plan(fn, task1.result, m)

     signal.signal()

     # task3 is run lazily when result property is accessed
     result3 = task3.result # TaskInterruptedException

except InterruptException:
     pass # won't happen since the interrupt is never signaled

Full documentation

Go to documentation

Metadata

Release files for runtime-threading 0.0.4

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

Source distribution (sdist)

Source distribution for runtime-threading 0.0.4
File Size Uploaded Provenance Actions
runtime_threading-0.0.4.tar.gz 41.7 kB With provenance Details for runtime_threading-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for runtime-threading 0.0.4
File Interpreter ABI Platform Actions
runtime_threading-0.0.4-py3-none-any.whl Python 3 none any Details for runtime_threading-0.0.4-py3-none-any.whl

Total release size: 98.2 kB

Release files / runtime_threading-0.0.4.tar.gz

Download URL runtime_threading-0.0.4.tar.gz
Size 41.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2a75b99bf63700465972faa440f0c048260bcfd4d0f46abbb6f1d64968344cf2
BLAKE2b-256 checksum
How to use checksums
6cb2c87da6694d535862b40e2d45479b7b74b2a2dd1c9554b2febeb6030b7636
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / runtime_threading-0.0.4-py3-none-any.whl

Download URL runtime_threading-0.0.4-py3-none-any.whl
Size 56.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8804b6d3820f36267d658be602b19f482a17cb121837b0f7045b4ea97d050b2f
BLAKE2b-256 checksum
How to use checksums
470863bf2237739fda536b8d1160e489a80e5119deb1e16bacd0163aba36ade4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Security for runtime-threading 0.0.4

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for runtime_threading-0.0.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

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.

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