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 work-stealing pool and 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 flume task queues, 64-byte padded atomic metrics, and parking_lot::Mutex synchronization state machines in the compiled _multiloop_core Rust extension (required at runtime):

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 flume work queues + parking_lot::Mutex waiter state machines
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: thread-local round-robin 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() 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.5

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.5
File Size Uploaded Provenance Actions
multiloop-0.1.5.tar.gz 278.0 kB With provenance Details for multiloop-0.1.5.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for multiloop 0.1.5
File Actions
multiloop-0.1.5-cp315-cp315t-win_amd64.whl CPython 3.15 CPython 3.15 free-threading Windows x86-64 Details for multiloop-0.1.5-cp315-cp315t-win_amd64.whl
multiloop-0.1.5-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.5-cp315-cp315t-manylinux_2_28_x86_64.whl
multiloop-0.1.5-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.5-cp315-cp315t-manylinux_2_28_aarch64.whl
multiloop-0.1.5-cp315-cp315t-macosx_11_0_arm64.whl CPython 3.15 CPython 3.15 free-threading macOS 11.0+ ARM64 Details for multiloop-0.1.5-cp315-cp315t-macosx_11_0_arm64.whl
multiloop-0.1.5-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.5-cp315-cp315t-macosx_10_12_x86_64.whl
multiloop-0.1.5-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details for multiloop-0.1.5-cp314-cp314t-win_amd64.whl
multiloop-0.1.5-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.5-cp314-cp314t-manylinux_2_28_x86_64.whl
multiloop-0.1.5-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.5-cp314-cp314t-manylinux_2_28_aarch64.whl
multiloop-0.1.5-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details for multiloop-0.1.5-cp314-cp314t-macosx_11_0_arm64.whl
multiloop-0.1.5-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.5-cp314-cp314t-macosx_10_12_x86_64.whl

Total release size: 5.9 MB

Release files / multiloop-0.1.5.tar.gz

Download URL multiloop-0.1.5.tar.gz
Size 278.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9ec9984852ca2ecd9de848423400d283ccfa9cca8c40b61b46c83311edd3832f
BLAKE2b-256 checksum
How to use checksums
e780eec494c83850b6c533bdafa596929bdd16e04b5cba6543b79c4e5fcc51dd
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.5-cp315-cp315t-win_amd64.whl

Download URL multiloop-0.1.5-cp315-cp315t-win_amd64.whl
Size 324.8 kB
Tags CPython 3.15 CPython 3.15 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
d33e8dc17215410430e56cdbf42e728b9f6a564897290379f3c031cfa468fb10
BLAKE2b-256 checksum
How to use checksums
a7767700006be66dde1f8dd3f25497ef0e349e38a48fc38ec1df4de95f1f1484
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.5-cp315-cp315t-manylinux_2_28_x86_64.whl

Download URL multiloop-0.1.5-cp315-cp315t-manylinux_2_28_x86_64.whl
Size 852.3 kB
Tags CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
5e78be49a282726331f2e93c510d317c0e6cf980d92c72e6759a68b8eefccb08
BLAKE2b-256 checksum
How to use checksums
b7e96eb491583deebaa4d0ad5d082068dcd7362ac93ccfe264e91f91ab394566
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.5-cp315-cp315t-manylinux_2_28_aarch64.whl

Download URL multiloop-0.1.5-cp315-cp315t-manylinux_2_28_aarch64.whl
Size 807.1 kB
Tags CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
ccd3d17f85f5d18572fe29ff36dbdd96847758fd3e10741d0f4d5a1f0e51e61c
BLAKE2b-256 checksum
How to use checksums
923a14774f3f37387d2d5420fae880d0da0626346d873d37f285eea606d2186a
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.5-cp315-cp315t-macosx_11_0_arm64.whl

Download URL multiloop-0.1.5-cp315-cp315t-macosx_11_0_arm64.whl
Size 418.5 kB
Tags CPython 3.15 CPython 3.15 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
021cea5f299044a038c39bfb84737be270a9a4a1bf4e25c8881004d043099394
BLAKE2b-256 checksum
How to use checksums
9745cfb8fbc854ea43c4dd1afcc5b06c060ae193466a246b1e9913d672f053a0
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.5-cp315-cp315t-macosx_10_12_x86_64.whl

Download URL multiloop-0.1.5-cp315-cp315t-macosx_10_12_x86_64.whl
Size 424.8 kB
Tags CPython 3.15 CPython 3.15 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
5fc3c557afa4e978f257f0897f001609eb56aa70a03c94d9f974abddcdbc2594
BLAKE2b-256 checksum
How to use checksums
1e845cc99658f0fa3e03fccaea70be5b66da686f9c1bed8bbaad8478c2346bfd
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.5-cp314-cp314t-win_amd64.whl

Download URL multiloop-0.1.5-cp314-cp314t-win_amd64.whl
Size 324.7 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
91ca2555b5f18c15e8cb432d304398c5960593826a7c3f32a10a84b3a6938ce8
BLAKE2b-256 checksum
How to use checksums
eba4cf8cd9b4df67681d847c0c9a6d8c86db0b234c81ab4148f1d2a869408196
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.5-cp314-cp314t-manylinux_2_28_x86_64.whl

Download URL multiloop-0.1.5-cp314-cp314t-manylinux_2_28_x86_64.whl
Size 852.2 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
f9dbfb901741f641c7e9ef216c58a23095631fcf2a86a880129a6b0f2acd1b83
BLAKE2b-256 checksum
How to use checksums
4f6c42621abcb5e20f645be2bdc456eb45242c1788bb6f2c190cc1af05c0415c
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.5-cp314-cp314t-manylinux_2_28_aarch64.whl

Download URL multiloop-0.1.5-cp314-cp314t-manylinux_2_28_aarch64.whl
Size 807.3 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
f6e8d85cfaa519b2f41ab8a257d43d8f934a37df5059686614a210c17e235c99
BLAKE2b-256 checksum
How to use checksums
feb70f1aae4d7cce64656d20ad4c3ff6b86e499c124c9cf4ca7a846adc782077
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.5-cp314-cp314t-macosx_11_0_arm64.whl

Download URL multiloop-0.1.5-cp314-cp314t-macosx_11_0_arm64.whl
Size 418.5 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c8fe2e6cb74b55b93465f6c80748ce52ff05f1a5b666fc38c4025a671cff8a2a
BLAKE2b-256 checksum
How to use checksums
e91580c57f1f1c27a5c071c7ecaf93660b986fbddf89fc35666418d4dbb8cf1f
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.5-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL multiloop-0.1.5-cp314-cp314t-macosx_10_12_x86_64.whl
Size 424.8 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
3805b69f8b4edaae0ea6f174a57d1d949c8d4d551d3e591d1dc2ba3b83bb02a6
BLAKE2b-256 checksum
How to use checksums
f04980b74536596d44fdac1f5c3b7a76b55476344c49c397a98d818b8c9797c3
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.5

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.5.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