HeadlinesBriefing favicon HeadlinesBriefing.com

runloom Brings Go-Style Goroutines to Free-Threaded Python

Hacker News •
×

runloom introduces Go-style stackful coroutines to Python 3.13t free-threaded builds, letting developers write blocking code that runs across every core without async/await. The library combines a hand-rolled assembly context switch (~80 ns), a C work-stealing scheduler with Chase-Lev deques, and netpoll (epoll/kqueue/IOCP) to park goroutines on file-descriptor readiness. A monkey.patch() call makes stdlib socket, time, and threading calls cooperative automatically, so existing blocking libraries run unchanged.

Benchmarks on a 64-core box show runloom beating Go on raw spawn throughput at 2.29M/s (C entry) versus Go's 2.10M/s, while Python-level fiber spawn hits 1.35M/s. Context-switch latency reaches ~75 ns yield and ~560 ns channel round-trip, matching Go's scheduler. Keep-alive echo throughput hits 596k req/s against Go's 603k req/s — parity with a Python handler, and a C handler beats Go. The honest gap is memory: an empty parked fiber carries a CPython eval frame at 8.8 KB versus Go's 2.7 KB, a 3.3× overhead.

The M:N work-stealing scheduler routes woken goroutines back to their origin hub, snapshots full PyThreadState (cframe, datastack, exc_info, contextvars), and includes stall isolation that detects and recovers from unexpected blocking calls. Prebuilt wheels ship for Linux x86_64/aarch64, macOS arm64/x86_64, and Windows AMD64 on CPython 3.11–3.14 with no runtime dependencies. An asyncio bridge (runloom.aio) offers a zero-rewrite port path for existing async code, though multi-core speedup requires the sync API with run(n>1, main).

The multi-core advantage only materializes on free-threaded CPython 3.13t+; on GIL builds runloom behaves like asyncio — cheap spawn and netpoll but single-core. Preemption fires at Python bytecode boundaries, so tight C extensions (numpy) still stall their hub. Linux x86_64 on 3.13t is the primary validated target with 2M-connection runs and fuzzing; other platforms are maintained but less exercised. For CPU-bound Python work, the ~80k ops/s/core ceiling remains; runloom's value is hitting that ceiling on every core simultaneously with a blocking mental model.