Skip to main content

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

CI Python 3.14t Rust Core Throughput License: MIT

⚡ A high-performance multi-event-loop concurrency toolkit and Web server engine for Python 3.14t (Free-Threaded / No-GIL), powered by an ultra-fast Rust SIMD 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.

Install with uv (Recommended)

# 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. Verified Performance & Benchmarks

Multi-Core Throughput (Python 3.14t)

multiloop achieves true physical multi-core scalability without GIL bottlenecks.

Production-grade wrk load benchmark metrics on Apple M1 (8 Cores, 8GB RAM, Python 3.14.6 Free-Threaded No-GIL, release build):

Workload (Benchmark Scenario) Single loop (1-Worker) multiloop 4-worker multiloop 8-worker Max Speedup Avg Latency
Plaintext 13B (GET /api/plaintext) 88,893 req/s 151,366 req/s 150,712 req/s 1.70x 0.29 ~ 0.74 ms
JSON Ping API (GET /api/ping) 79,079 req/s 142,622 req/s 145,836 req/s 1.84x 0.31 ~ 0.64 ms
CPU-bound Dispatch (40 × 2M ops) 2.88 s 0.79 s 0.60 s 4.83x —

Reproducing Benchmarks

Run the high-performance C-based wrk benchmark suite to measure physical multi-core throughput:

# Measure real throughput via wrk (zero client CPU overhead)
uv run python benchmarks/bench_wrk_asgi.py --duration 5 --concurrency 100 --workers 1,4,8

You can also run the built-in cross-platform pure-Python socket benchmark suite directly (zero external dependencies required):

uv run python benchmarks/bench_asgi_throughput.py

3. Web Server CLI

multiloop includes a high-performance CLI server runner. Unlike traditional multi-process process managers (gunicorn -w 4 or uvicorn --workers 4), multiloop run operates across multi-threaded isolated event loops in a single process with shared memory and zero IPC serialization overhead.

Run a FastAPI Application

Create main.py:

from fastapi import FastAPI

app = FastAPI(title="My multiloop API")


@app.get("/")
def read_root():
    return {"message": "Hello from FastAPI on multiloop!"}

Start the multi-worker server with 1 command:

multiloop run main:app --port 8000 --workers 4 --reload

Open http://127.0.0.1:8000/docs to view the live interactive Swagger UI!

Run a Flask or Django Application

multiloop run automatically detects WSGI applications (PEP 3333). Create app.py:

from flask import Flask

app = Flask(__name__)


@app.route("/")
def index():
    return "Hello from Flask running on multiloop WSGI thread pool!"

Launch the WSGI application with multi-thread pool offloading:

multiloop run app:app --port 5000 --workers 4

CLI Parameter Reference

multiloop run <module:app> [OPTIONS]
Option Default Description
<module:app> (Required) Application import string, e.g. main:app or my_project.wsgi:application
--host 127.0.0.1 Network interface to bind on (0.0.0.0 for public access)
--port 8000 Port to bind on (0 for ephemeral random port)
--workers auto Number of worker event loop threads (defaults to CPU core count)
--reload off Enable automatic hot-reloading upon file modifications
--interface auto Protocol interface: auto, asgi (FastAPI/Starlette), or wsgi (Django/Flask)
--log-level info Logging verbosity: debug, info, warning, error

4. Python API Usage

1. Multi-Core Thread Pool (asyncssh style)

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 an async coroutine (shared queue + work-stealing scheduler)
        fut1 = pool.submit(heavy_task, 21)

        # Target a specific worker loop (stateful connection affinity)
        fut2 = pool.submit(heavy_task, 21, pin_to=0)

        # Await results computed across physical CPU cores
        print("Results:", await fut1, await fut2)  # Output: 42 42


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

2. Go-Style Channel & select_channel

import asyncio
import multiloop


async def main() -> None:
    ch1: multiloop.Channel[str] = multiloop.Channel()
    ch2: multiloop.Channel[str] = multiloop.Channel()

    async def producer() -> None:
        await ch1.send("Data from Channel 1")
        ch1.close()

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


5. 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 / FastAPI / ASGI 3.0] -->|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]
    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 (355+ tests)
make test

6. Miscellaneous & Community

Known Limits & Invariants

Limit Detail Escape hatch
Requires Python 3.14t Free-threaded CPython is experimental (PEP 703) Pin Python 3.14t environment
Barrier + cancelled party Cancelled party before round completion parks remainder Use abort() on exception
select_channel arbitration Non-consuming readiness check under high contention Built-in re-register loop
Waiter removal is O(n) Cancelling N parked waiters scales as O(n²) Keep party counts realistic
AsyncContext.cancel() Cancels awaiters rather than active pool coroutines Design tasks to observe future
CancelScope shield Absorbs pre-injected cancellations Use retry-loop pattern
Windows Proactor: single acceptor listener model Documented platform behavior

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

Live Demo

Want to test a live production setup without writing code? multiloop-fastapi-demo is a real FastAPI application served directly by multiloop run / MultiloopASGIWorker without uvicorn:

git clone https://github.com/hankaihong1/multiloop-fastapi-demo
cd multiloop-fastapi-demo
uv sync
uv run python app.py        # then open http://127.0.0.1:8000

Community & License

Metadata

Release files for multiloop 0.1.2

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.2
File Size Uploaded
multiloop-0.1.2.tar.gz 261.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for multiloop 0.1.2
File
multiloop-0.1.2-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
multiloop-0.1.2-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.2-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.2-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
multiloop-0.1.2-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.2-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
multiloop-0.1.2-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.2-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ ARM64 Details
multiloop-0.1.2-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
multiloop-0.1.2-cp314-cp314-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.12+ x86-64 Details

Total release size: 3.8 MB

Release files / multiloop-0.1.2.tar.gz

Download URL multiloop-0.1.2.tar.gz
Size 261.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bb53cb8aee0d1666c90767a262c8febf705ed3f440116dca2176463523b09d96
BLAKE2b-256 checksum
How to use checksums
552cbafa0a7cc6b122649e5aeda88c79db8f0b2bd2783b4286b3428f61a48b71
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 Aug 21, 2026.

Transparency log

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

Download URL multiloop-0.1.2-cp314-cp314t-win_amd64.whl
Size 298.2 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
f7b145cb46d04b134397297b50cbe6990581271f811b589992693ab9cfaa86c8
BLAKE2b-256 checksum
How to use checksums
f407e8da1c73b16d7f2f8fc92b4c3c5ba4f5c14f1da1402956455be3de93a26f
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 Aug 21, 2026.

Transparency log

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

Download URL multiloop-0.1.2-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 372.4 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7ffb5f270bd2743e704fd346cfe8f87d12c88a7b0ccdae6f915a47a32a26ec92
BLAKE2b-256 checksum
How to use checksums
3eb63d15cb635e89f37885d21058be25b4373413b9db7c05e02b50864e7e72a9
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 Aug 21, 2026.

Transparency log

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

Download URL multiloop-0.1.2-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 362.2 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
cf0b39e347d4e40785987741f9fa82f9448b34d7b375955abc95847655a806d0
BLAKE2b-256 checksum
How to use checksums
e06a0b205ab0318222d934aca335a3d9333c23ceb428d8b1ae36070e9d1c1a3a
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 Aug 21, 2026.

Transparency log

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

Download URL multiloop-0.1.2-cp314-cp314t-macosx_11_0_arm64.whl
Size 349.0 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
05b9f6ffee6a44a3477aaa6463679d269a5c3ceb3418c30c7eb5f6513b2ac53d
BLAKE2b-256 checksum
How to use checksums
3c7fa623f9f3eb2f40523e659e9e46fa30c5dd85609d8f10b2fa0b5f8c8b95fb
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 Aug 21, 2026.

Transparency log

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

Download URL multiloop-0.1.2-cp314-cp314t-macosx_10_12_x86_64.whl
Size 363.0 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c0f388a781707f8b016061535d8162fc5ad26dd2ffde4b9c05cc96239989c3f6
BLAKE2b-256 checksum
How to use checksums
0a785a761116cfe72db9e5ea348edb4b2ba16e7ae2722e9b193dc3e71eab85ea
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 Aug 21, 2026.

Transparency log

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

Download URL multiloop-0.1.2-cp314-cp314-win_amd64.whl
Size 299.6 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
8b29f98235c340513c4c9b85a488b85943fecf4c54e8fbc97d392eae3341c8c1
BLAKE2b-256 checksum
How to use checksums
20203cf336ba3020a9daa634c27e7b0ec81f2f23b80c29bbb9ac2d24070041da
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 Aug 21, 2026.

Transparency log

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

Download URL multiloop-0.1.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 374.6 kB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
90dfe2fba9b7d5a54a0372db0313f9867f2e2633a7229ebb4b5ed47ccbcfbd83
BLAKE2b-256 checksum
How to use checksums
bfb57aa8e305f78812446f08bb6f11d17aca072b24f74fefc1b67ce50ee5804b
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 Aug 21, 2026.

Transparency log

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

Download URL multiloop-0.1.2-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 364.5 kB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
668c5a139610d0c63522dbaf0977765cb4172eea8eff459ea7216df2f93bf25f
BLAKE2b-256 checksum
How to use checksums
4eaad76460502b58f3013bb915ef24544be8e99740b424c2379f554d3df820a1
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 Aug 21, 2026.

Transparency log

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

Download URL multiloop-0.1.2-cp314-cp314-macosx_11_0_arm64.whl
Size 351.8 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
89cbdb798ab1e16d59b5cf57cc87903c9956e8b46f24f2ab7d0fdbca6eedbdfb
BLAKE2b-256 checksum
How to use checksums
e87e0c86c7d61b192f90a53d360652a31e57365d6e541734378eab7cc707daf3
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 Aug 21, 2026.

Transparency log

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

Download URL multiloop-0.1.2-cp314-cp314-macosx_10_12_x86_64.whl
Size 365.9 kB
Tags CPython 3.14 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
20a60e74bc0ce8c5e2290999d3c1fbfe4beecb34ee91766391537d5cabc88054
BLAKE2b-256 checksum
How to use checksums
a8c3d87321ceb3ed68ced111c8b57eda07c507fa18ddf1491162d94096e40dab
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 Aug 21, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.3

11 release files

This release

0.1.2 This release

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