Skip to main content

multiloop: Multi-Event-Loop Engine & Concurrency Toolkit for Python 3.14t

CI Python 3.14t Rust Core License: MIT

⚡ A high-performance multi-event-loop concurrency engine and Go-style concurrency toolkit for Python 3.14t (Free-Threaded / No-GIL), powered by an ultra-fast Rust core.

中文版 (Chinese)


Table of Contents


1. Installation

Prerequisites

  • Python 3.14+: Free-Threaded (no-GIL) build, e.g. python3.14t.
  • Rust Toolchain: Stable (via rustup) to compile the _multiloop_core Rust extension.
# Add multiloop to your project
uv add multiloop

# Or install into the current active virtual environment
uv pip install multiloop

Install with pip

pip install multiloop

Build from source

# Clone and compile optimized release extension via maturin
git clone https://github.com/hankaihong1/multiloop.git
cd multiloop
maturin develop --release

2. Multi-Core Performance & Benchmarks

Multi-Core Throughput (Python 3.14t)

multiloop achieves true physical multi-core scalability without GIL bottlenecks across isolated event loops.

Multi-core scheduling and throughput benchmarks on Apple M1 (8 Cores, 8GB RAM, Python 3.14.6 Free-Threaded No-GIL, release build):

Workload (Benchmark Scenario) 1 Worker Loop 4 Worker Loops 8 Worker Loops Max Speedup
CPU-bound Dispatch (40 × 2M ops) 2.88 s 0.79 s 0.60 s 4.83x
Cross-Thread Channel Ping-Pong (100k) 185k msgs/s 340k msgs/s 410k msgs/s 2.21x

Reproducing Benchmarks

Run the built-in multi-thread benchmark suite to measure physical multi-core throughput:

# Measure multi-thread loop pool scaling
uv run python benchmarks/bench_multithread_loops.py

# Measure lock-free work stealing channel pull throughput
uv run python benchmarks/benchmark_pull_model.py

3. Python API Usage

1. Multi-Core Thread Pool

import asyncio
import multiloop


async def heavy_task(x: int) -> int:
    await asyncio.sleep(0.01)
    return x * 2


async def main() -> None:
    # async with manages the pool lifecycle automatically
    async with multiloop.EventLoopThreadPool(num_threads=4) as pool:
        # submit() round-robins across workers with work stealing
        fut = pool.submit(heavy_task, 42)
        result = await fut
        print(f"Computed result: {result}")


if __name__ == "__main__":
    asyncio.run(main())

2. Go-Style Channels & select_channel

import asyncio
import multiloop


async def main() -> None:
    ch1 = multiloop.Channel(maxsize=10)
    ch2 = multiloop.Channel(maxsize=10)

    async def producer() -> None:
        await ch1.send("Message from Worker A")

    asyncio.create_task(producer())

    # select_channel waits for the first channel that becomes ready
    selected_ch, val = await multiloop.select_channel(ch1, ch2)
    print(f"Received: {val}")


if __name__ == "__main__":
    asyncio.run(main())

3. Task Synchronization with AsyncWaitGroup

import asyncio
import multiloop


async def worker(name: str, wg: multiloop.AsyncWaitGroup) -> None:
    try:
        await asyncio.sleep(0.02)  # simulated asynchronous work
        print(f"worker {name} done")
    finally:
        wg.done()  # decrement counter safely on completion or error


async def main() -> None:
    wg = multiloop.AsyncWaitGroup()

    # Dispatch 5 tasks across a 4-thread pool
    async with multiloop.EventLoopThreadPool(num_threads=4) as pool:
        for i in range(5):
            wg.add()  # increment counter
            pool.submit(worker, f"task-{i}", wg)

        # Block until all tasks finish (counter reaches zero)
        await wg.wait()
        print("All workers finished cleanly!")


if __name__ == "__main__":
    asyncio.run(main())

4. Structured Concurrency with TaskGroup

import asyncio
import multiloop


async def fetch(name: str, delay: float) -> str:
    await multiloop.sleep(delay)  # simulated cancellable work
    return f"{name}: ok"


async def main() -> None:
    try:
        # fail_after sets an overall deadline for the entire taskgroup
        async with multiloop.fail_after(0.1):
            async with multiloop.TaskGroup() as tg:
                h1 = tg.start_soon(fetch, "fast", 0.01)
                h2 = tg.start_soon(fetch, "slow", 0.5)

            print(await h1, "|", await h2)
    except TimeoutError:
        print("Timed out: child tasks cancelled safely")


if __name__ == "__main__":
    asyncio.run(main())

Explore more standalone scripts in examples/.


4. Architecture & Developer Guide

Core Architecture

multiloop assigns an isolated asyncio event loop to each worker OS thread, backed by lock-free task queues and padded atomic metrics in Rust:

graph TD
    UserApp[User Application / Task Pipeline] -->|pool.submit| Scheduler[Round-Robin Scheduler]
    
    subgraph multiloop Core Engine
        Scheduler -->|Round-Robin Notify| W1[Worker Loop Thread 1]
        Scheduler -->|Round-Robin Notify| W2[Worker Loop Thread 2]
        Scheduler -->|Round-Robin Notify| W3[Worker Loop Thread 3]
        
        W1 <-->|Atomic Metrics| RustCore[Rust C-Extension _multiloop_core]
        W2 <-->|Atomic Metrics| RustCore
        W3 <-->|Atomic Metrics| RustCore
    end
    
    subgraph Golang Concurrency Toolkit
        RustCore <--> FastChan[Channel / RawAsyncChannel]
        FastChan <--> Select[multiloop.select_channel]
        FastChan <--> Context[AsyncContext]
        RustCore <--> WaitGroup[AsyncWaitGroup]
        RustCore <--> RWMutex[AsyncRWMutex]
    end

Local Development & Testing Gates

# 1. Build and install release Rust extension
make develop

# 2. Run all linter & type checks (0 warnings, strict typing)
make lint

# 3. Run complete test suite (490+ tests)
make test

5. Miscellaneous & Community

Formal Concurrency Guarantees

Invariant / Primitive Physical Concurrency Guarantee Underlying State Machine
Python 3.14t Free-Threading Physical multi-core parallelism across isolated event loops Lock-free Rust queues + OS mutex protected waiter lists
Barrier Cancellation Auto-healing: cancelled party immediately breaks round & wakes all waiters Monotonic generation counter + Rust RawAsyncBarrier state machine
select_channel Arbitration 100% deterministic arbitration without message loss or starvation Two-phase arbiter: uniform random probe + single-arbiter registration
Waiter Cancellation Safe ticketed cancellation immune to ABA pointer reuse Monotonic Rust WaiterId (u64) tickets + out-of-lock call_soon_threadsafe
AsyncContext.cancel() Directly cancels active coroutines on worker OS threads Injected CancelScope cross-thread cancellation
CancelScope Shielding Zero-leak scope isolation without touching task.cancelling() Route 3 pure Rust RawTaskCancelState task cancel stack

For formal invariants and concurrency design principles, see docs/CONCURRENCY.md.

Community & License

Metadata

Release files for multiloop 0.1.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 multiloop 0.1.4
File Size Uploaded Provenance Actions
multiloop-0.1.4.tar.gz 250.3 kB With provenance Details for multiloop-0.1.4.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for multiloop 0.1.4
File Actions
multiloop-0.1.4-cp315-cp315t-win_amd64.whl CPython 3.15 CPython 3.15 free-threading Windows x86-64 Details for multiloop-0.1.4-cp315-cp315t-win_amd64.whl
multiloop-0.1.4-cp315-cp315t-manylinux_2_28_x86_64.whl CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ x86-64 Details for multiloop-0.1.4-cp315-cp315t-manylinux_2_28_x86_64.whl
multiloop-0.1.4-cp315-cp315t-manylinux_2_28_aarch64.whl CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ ARM64 Details for multiloop-0.1.4-cp315-cp315t-manylinux_2_28_aarch64.whl
multiloop-0.1.4-cp315-cp315t-macosx_11_0_arm64.whl CPython 3.15 CPython 3.15 free-threading macOS 11.0+ ARM64 Details for multiloop-0.1.4-cp315-cp315t-macosx_11_0_arm64.whl
multiloop-0.1.4-cp315-cp315t-macosx_10_12_x86_64.whl CPython 3.15 CPython 3.15 free-threading macOS 10.12+ x86-64 Details for multiloop-0.1.4-cp315-cp315t-macosx_10_12_x86_64.whl
multiloop-0.1.4-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details for multiloop-0.1.4-cp314-cp314t-win_amd64.whl
multiloop-0.1.4-cp314-cp314t-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64 Details for multiloop-0.1.4-cp314-cp314t-manylinux_2_28_x86_64.whl
multiloop-0.1.4-cp314-cp314t-manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64 Details for multiloop-0.1.4-cp314-cp314t-manylinux_2_28_aarch64.whl
multiloop-0.1.4-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details for multiloop-0.1.4-cp314-cp314t-macosx_11_0_arm64.whl
multiloop-0.1.4-cp314-cp314t-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 Details for multiloop-0.1.4-cp314-cp314t-macosx_10_12_x86_64.whl

Total release size: 5.8 MB

Release files / multiloop-0.1.4.tar.gz

Download URL multiloop-0.1.4.tar.gz
Size 250.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2e78ce16f58f0c6c6fee2a7649b45975954741295fd44454d75ca909536325c2
BLAKE2b-256 checksum
How to use checksums
11d28652568973bac34051a7369c94292d88e96369e22eaa95648b1c2fbdfba2
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 Nov 22, 2026.

Transparency log

Release files / multiloop-0.1.4-cp315-cp315t-win_amd64.whl

Download URL multiloop-0.1.4-cp315-cp315t-win_amd64.whl
Size 310.7 kB
Tags CPython 3.15 CPython 3.15 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
887286c5c5df46e6fd9a684ae612b67d1d368c2cc7d9c0845b7a5b40d4ae01e0
BLAKE2b-256 checksum
How to use checksums
3e3485b90c6d9e40c1bfa376b2bd2d7b4ae34687d543be2710cb1fcff7cb4144
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 Nov 22, 2026.

Transparency log

Release files / multiloop-0.1.4-cp315-cp315t-manylinux_2_28_x86_64.whl

Download URL multiloop-0.1.4-cp315-cp315t-manylinux_2_28_x86_64.whl
Size 840.8 kB
Tags CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
74d27e07948c9702fc11636aab36f0d52c503d45d54b7c4041e69c5f7a799b47
BLAKE2b-256 checksum
How to use checksums
24f8e26e5518f3fd0cc78bd1e8c45f982730f485f543e60ea35c91a4998687b7
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 Nov 22, 2026.

Transparency log

Release files / multiloop-0.1.4-cp315-cp315t-manylinux_2_28_aarch64.whl

Download URL multiloop-0.1.4-cp315-cp315t-manylinux_2_28_aarch64.whl
Size 794.8 kB
Tags CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
74032d6908793edbc6d073f89a2a4dc296e4771c039fbd892e1d29dfa24e9581
BLAKE2b-256 checksum
How to use checksums
7ad788d4e5510aa858d15bc2872b4ba504cfddf2ec6ed522e2b0ec01feae39cc
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 Nov 22, 2026.

Transparency log

Release files / multiloop-0.1.4-cp315-cp315t-macosx_11_0_arm64.whl

Download URL multiloop-0.1.4-cp315-cp315t-macosx_11_0_arm64.whl
Size 407.1 kB
Tags CPython 3.15 CPython 3.15 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
dd9892c752936889254a28be7fd972ba9b86553c6548c180d5d73f3ddd7358b1
BLAKE2b-256 checksum
How to use checksums
b71fea6e4a850e4f25253eef64e22be09ea0f6caada8f3a2eecaebd6dfe99ec5
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 Nov 22, 2026.

Transparency log

Release files / multiloop-0.1.4-cp315-cp315t-macosx_10_12_x86_64.whl

Download URL multiloop-0.1.4-cp315-cp315t-macosx_10_12_x86_64.whl
Size 410.8 kB
Tags CPython 3.15 CPython 3.15 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
916e6f89bd487610ec42685bfbb19dba8b4b06a5690a5ae845b3d1f96e14e1f7
BLAKE2b-256 checksum
How to use checksums
15d5bc84bb077f24a9e08d00aa6137e958b8dffbd1d4121428d52042291eaba3
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 Nov 22, 2026.

Transparency log

Release files / multiloop-0.1.4-cp314-cp314t-win_amd64.whl

Download URL multiloop-0.1.4-cp314-cp314t-win_amd64.whl
Size 310.5 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
1564c00ce35d3ad5fc4eaa590e611aadda73eeddc88acf147e677f74007e9167
BLAKE2b-256 checksum
How to use checksums
f93fe68a0acd78be810b56af42ba18a92691d1019ed86473f6992fba50c1b791
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 Nov 22, 2026.

Transparency log

Release files / multiloop-0.1.4-cp314-cp314t-manylinux_2_28_x86_64.whl

Download URL multiloop-0.1.4-cp314-cp314t-manylinux_2_28_x86_64.whl
Size 840.7 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
96b6f1d85335fc623bb376690681bd5e34646c998047c93ef915e079aa99efa2
BLAKE2b-256 checksum
How to use checksums
997c62a6d3109a9a463f9db59030ace1891bd08464fdf321af38c22981398cb9
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 Nov 22, 2026.

Transparency log

Release files / multiloop-0.1.4-cp314-cp314t-manylinux_2_28_aarch64.whl

Download URL multiloop-0.1.4-cp314-cp314t-manylinux_2_28_aarch64.whl
Size 795.0 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
3c73962a4c9b0f79a4a25639ef6b4e649cca34df4d0b6f9cd85bdc76d45f7903
BLAKE2b-256 checksum
How to use checksums
e28873af439c41ef02ac6eca74ffe8215122217ac148cfeaec9a9b5110fba439
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 Nov 22, 2026.

Transparency log

Release files / multiloop-0.1.4-cp314-cp314t-macosx_11_0_arm64.whl

Download URL multiloop-0.1.4-cp314-cp314t-macosx_11_0_arm64.whl
Size 407.1 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b5f74c94d3ade39de72eb9cfd2ce92725f6676f70b7f5c98010069aa42db40ee
BLAKE2b-256 checksum
How to use checksums
d5adac82ccc932d430ad296f263192d37a24cdd0f24bad4012a3cc85d095a92a
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 Nov 22, 2026.

Transparency log

Release files / multiloop-0.1.4-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL multiloop-0.1.4-cp314-cp314t-macosx_10_12_x86_64.whl
Size 410.8 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
65d45c5a10c1840a59ae7b5e270e48aa3131b2861f99f538a9dd7d6f6076f0f3
BLAKE2b-256 checksum
How to use checksums
69ff9e4a83a18c44f972fc3d164d211369fad2b778e498c209db98c0f60658a1
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 Nov 22, 2026.

Transparency log

Security for multiloop 0.1.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

All 11 files in this release have been uploaded with provenance metadata.

Select from 11 files

Attestation for multiloop-0.1.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 Nov 22, 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