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 asyncio.sleep(delay)  # simulated network latency
    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 / flume]
        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 (320+ 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 + atomic _broken state machine
select_channel Arbitration 100% deterministic arbitration without message loss or starvation Two-phase arbiter: uniform random probe + single-arbiter registration
Waiter Unregistration $O(1)$ constant time cancellation per waiter collections.OrderedDict hash lookup & removal
AsyncContext.cancel() Directly cancels active coroutines on worker OS threads Injected CancelScope cross-thread cancellation
CancelScope Shielding Zero-leak symmetric cancellation accounting CPython 3.11+ task.cancelling() snapshot & restore

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

Community & License

Metadata

Release files for multiloop 0.1.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 multiloop 0.1.3
File Size Uploaded
multiloop-0.1.3.tar.gz 209.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for multiloop 0.1.3
File
multiloop-0.1.3-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
multiloop-0.1.3-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 Details
multiloop-0.1.3-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 Details
multiloop-0.1.3-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
multiloop-0.1.3-cp314-cp314t-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 Details
multiloop-0.1.3-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
multiloop-0.1.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
multiloop-0.1.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ ARM64 Details
multiloop-0.1.3-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
multiloop-0.1.3-cp314-cp314-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.12+ x86-64 Details

Total release size: 5.0 MB

Release files / multiloop-0.1.3.tar.gz

Download URL multiloop-0.1.3.tar.gz
Size 209.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7cc93915e7e7958c3fced07b384bcce8e5faa47ebaf0e5c0ed47925ef175e58e
BLAKE2b-256 checksum
How to use checksums
26c74c4dd5b8945c48afb136e5338dcd3f91665bc3bcf951690dc93f8c6b4013
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

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

Download URL multiloop-0.1.3-cp314-cp314t-win_amd64.whl
Size 238.8 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
44280759ee7d8b93c2e92f93d5cf393eae80862e41ec46628b95292856ec0b40
BLAKE2b-256 checksum
How to use checksums
43e169b46d2295c40a012c84df35695eb0781777f980a7098a59946e2b8a72b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

Release files / multiloop-0.1.3-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL multiloop-0.1.3-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 771.8 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4636e2281e3f60ffa7da641f0640c82336a558b739be2364563995627376e795
BLAKE2b-256 checksum
How to use checksums
add1e3442ada94465c4e26dabd7670ab90b8541cb0a678b5e95c5bf74bee359e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

Release files / multiloop-0.1.3-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL multiloop-0.1.3-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 723.5 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
e1d2c019616ba3c16e714cfe92e6308ac5ec4f574cbbccf34f97e3cf7e337004
BLAKE2b-256 checksum
How to use checksums
a9523f9fe0259fd6b0f208df76645eda81b99a1215c3886facca4db9dde8c8d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

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

Download URL multiloop-0.1.3-cp314-cp314t-macosx_11_0_arm64.whl
Size 337.7 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6471d82baaa9abf240c390173a232d78b6a988dd390e552908f1b0f8ddd24b5c
BLAKE2b-256 checksum
How to use checksums
05624e19d04da83f1f9f41350cb608416a172943baafb4be4fcc3564cab2ab51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

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

Download URL multiloop-0.1.3-cp314-cp314t-macosx_10_12_x86_64.whl
Size 342.7 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d74263a10c2fa08ef9846940971a75b02290d450f1a904061a8f7f5fd78312a9
BLAKE2b-256 checksum
How to use checksums
308bc2a593a7b2500ce12be6994b9afbe001aaebf4eb3dbe9ef558a24eeaeb10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

Release files / multiloop-0.1.3-cp314-cp314-win_amd64.whl

Download URL multiloop-0.1.3-cp314-cp314-win_amd64.whl
Size 238.8 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
283609ee2b8e623ab57863f62c261639511acf9651b594b8a20bf56e0a46b82f
BLAKE2b-256 checksum
How to use checksums
5dfad5d142dd3a7442b36e835a0554b040e5c82d9bb18e895601e754c751cf8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

Release files / multiloop-0.1.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL multiloop-0.1.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 773.0 kB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
199bb767e12c3756b3d893aed6ab9818fd36641235fb6d8a33616932955580c9
BLAKE2b-256 checksum
How to use checksums
fd0dcb32a62facca486985739f0ae7dfac49cb5194a984dff8c9c568e24cded8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

Release files / multiloop-0.1.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL multiloop-0.1.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 725.3 kB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
afa0e292ea104e6146c334031186fe553f29063b063cb24550b6c75f0a9cd251
BLAKE2b-256 checksum
How to use checksums
643621fb4c320b8f39d60cee0337a7fe44b4c49960ab53c9f6d1d40fefd13b67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

Release files / multiloop-0.1.3-cp314-cp314-macosx_11_0_arm64.whl

Download URL multiloop-0.1.3-cp314-cp314-macosx_11_0_arm64.whl
Size 339.3 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b2f4becbc17bb1c3d2f8b4f0627301d1d813aa317498216f11bef52ee34e7cdc
BLAKE2b-256 checksum
How to use checksums
9208257082ac61f15eba4a384fa91304ec4fa501288e85f68784c9e96bffe3c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

Release files / multiloop-0.1.3-cp314-cp314-macosx_10_12_x86_64.whl

Download URL multiloop-0.1.3-cp314-cp314-macosx_10_12_x86_64.whl
Size 344.5 kB
Tags CPython 3.14 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a1a0a105e5904cd85df1891a473c0cdbc288e121241188984cc892fb15be0ec7
BLAKE2b-256 checksum
How to use checksums
96246f62f4770f8786da5c530ef989a1e949388967091dcad8275d50f2eb57ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

11 release files

0.1.2

11 release files

0.1.1

11 release files

0.1.0

11 release files

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