An experimental multi-interpreter server/framework for Python.
Project description
multicorn
Multicorn is an experimental multi-interpreter server/framework for Python.
Motivation
For a long time, Python programmers were suffered from Python's GIL issue when building server-side applications. To fully use the multiple CPU cores on modern machines, we have to use multi-processing since one python interpreter instance can only use one CPU core because of the GIL.
This caused huge memory costs and made stateful server programming harder because we can't share data between processes easily.
PEP 734 brings the new hope: it adds the concurrent.interpreters module to the standard library (Python 3.14), so we can have multiple python interpreters in one process. Combined with the per-interpreter GIL from PEP 684 (Python 3.12), every interpreter has its own GIL and all the interpreters can run in parallel.
Multicorn is an experimental project for writing server-side network applications in multi-interpreters. It's more like a multi-interpreter version of gunicorn, instead of using multi-process.
Usage
Write a WSGI application as usual:
# myapp.py
def app(environ, start_response):
start_response("200 OK", [("Content-Type", "text/plain")])
return [b"Hello from multicorn!\n"]
Then serve it with multiple interpreters, each running in its own thread and sharing the listening socket:
import multicorn
server = multicorn.Server(
"multicorn.workers:WSGIWorker",
["myapp:app"],
workers_count=4,
)
server.run(("localhost", 3000))
Now curl http://localhost:3000/ is served by one of the four sub-interpreters.
Async (ASGI) applications are supported as well:
# myasgi.py
async def app(scope, receive, send):
assert scope["type"] == "http"
await send({
"type": "http.response.start",
"status": 200,
"headers": [(b"content-type", b"text/plain")],
})
await send({
"type": "http.response.body",
"body": b"Hello from multicorn!\n",
})
import multicorn
server = multicorn.Server(
"multicorn.workers:ASGIWorker",
["myasgi:app"],
workers_count=4,
)
server.run(("localhost", 3000))
The ASGI worker speaks HTTP/1.1 and supports the optional lifespan protocol; apps that don't implement lifespan keep working unchanged.
Current status
- Support run WSGI server in multi-interpreters.
- Support run ASGI server in multi-interpreters.
- Manage the life cycle of sub-interpreters.
Limitations
Multicorn uses the concurrent.interpreters module from PEP 734. On Python 3.14 or later this module is available in the standard library; on earlier versions it is provided by the backports.interpreters package, so Python 3.8 or later is required.
True multi-core parallelism relies on the per-interpreter GIL introduced in PEP 684, which is only available on Python 3.12 and later. On Python 3.11 or earlier all sub-interpreters share a single GIL, so multicorn runs but can not use multiple CPU cores in one process.
License
Multicore is distributed by a MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multicorn-0.2.0.tar.gz.
File metadata
- Download URL: multicorn-0.2.0.tar.gz
- Upload date:
- Size: 42.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b760b5822191c09fe2b539b27eb113ffeb039d028258062ad83b33e92b247b0
|
|
| MD5 |
9e0c0cfcede2e3cfc320289540bb3187
|
|
| BLAKE2b-256 |
9d9ec457619e1ea15c2567bf0ef1249da9fcecaa8fb1f2ce56b867bc047ee224
|
File details
Details for the file multicorn-0.2.0-py3-none-any.whl.
File metadata
- Download URL: multicorn-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9fe031a2561121e11c02bbd5eeccd1e2a6301ef28a2247c9082ccad1a1fa9f2
|
|
| MD5 |
4d270860ce815237e93db3301e661fe0
|
|
| BLAKE2b-256 |
2abebaf7e8af0a154afc39acfc19263b2b8cd09def1cd26859590f11e91196a8
|