Skip to main content

multicorn

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.

Metadata

Release files for multicorn 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for multicorn 0.2.0
File Size Uploaded
multicorn-0.2.0.tar.gz 42.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for multicorn 0.2.0
File Interpreter ABI Platform
multicorn-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.9 kB

Release files / multicorn-0.2.0.tar.gz

Download URL multicorn-0.2.0.tar.gz
Size 42.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5b760b5822191c09fe2b539b27eb113ffeb039d028258062ad83b33e92b247b0
BLAKE2b-256 checksum
How to use checksums
9d9ec457619e1ea15c2567bf0ef1249da9fcecaa8fb1f2ce56b867bc047ee224
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / multicorn-0.2.0-py3-none-any.whl

Download URL multicorn-0.2.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9fe031a2561121e11c02bbd5eeccd1e2a6301ef28a2247c9082ccad1a1fa9f2
BLAKE2b-256 checksum
How to use checksums
2abebaf7e8af0a154afc39acfc19263b2b8cd09def1cd26859590f11e91196a8
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 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