Runloom Brings Go-Style Coroutines to Free-Threaded Python
An open-source library implements stackful coroutines to skip <code>async/await</code> syntax, but unlocking full performance still requires running free-threaded Python.
A community project called Runloom wants to bring Go-style concurrency to Python. Instead of forcing developers to pepper code with async and await keywords, the tool introduces stackful coroutines that yield execution during I/O operations under the hood.
The runtime architecture leans heavily on lower-level primitives: an assembly-based context switcher, a C-based work-stealing scheduler, integration with a netpoll stack, and runtime monkeypatching via monkey.patch(). By intercepting standard blocking calls in modules like socket, time, and threading, the library suspends the coroutine while keeping the operating system thread active on other tasks. It also features a bridge to run existing asyncio tasks.
According to the project author's benchmarks, raw task creation in pure C reached 2.29 million operations per second, edging out Go's 2.10 million. However, invoking task creation directly from Python drops throughput to 1.35 million operations per second, roughly 65% of Go's baseline. Network throughput under keep-alive tests remained competitive at 596,000 requests per second compared to 603,000 in Go.
The approach carries notable trade-offs. Each suspended coroutine consumes about 3.3 times more memory than a standard goroutine because it must retain CPython call frame structures. Furthermore, achieving actual parallel execution across multiple CPU cores depends entirely on Python 3.13t+ built with the Global Interpreter Lock (GIL) disabled; running it under a standard build limits the library to a syntactic alternative for existing asynchronous engines without significant throughput gains.
Source: habr
Comments
Help shape the next version: Add context or suggest a correction. AI review can add points toward a rewrite. Reviews and updates may take time; a full meter does not guarantee a new version.