polar icon indicating copy to clipboard operation
polar copied to clipboard

Python free-threading support

Open frankie567 opened this issue 1 month ago • 0 comments
trafficstars

Now that free-threading (aka no-GIL) is a thing in Python 3.14, it could be interesting to explore if we can migrate to that. Not sure what kind of performance gain we could get, but it's worth to check.

The main blockers right now are libraries with C extensions that have not been adapted yet to this new mode.

Dependency blockers

  1. sqlalchemy (ready, to release in 2.1): https://github.com/sqlalchemy/sqlalchemy/issues/12881
    • but... asyncio features rely on greenlet, which doesn't seem to aim at supporting free-threading: https://github.com/python-greenlet/greenlet/issues/423
  2. asyncpg: https://github.com/MagicStack/asyncpg/pull/1279
  3. httptools (dependency of Uvicorn): https://github.com/MagicStack/httptools/issues/118

Experiments

2025-10-18

Tried to run the API with:

  • env PYTHON_GIL=0 to avoid greenlet warning
  • Installed asyncpg from https://github.com/MagicStack/asyncpg/pull/1279
  • --http h11 option of Uvicorn to avoid 3

Server is starting, can serve a few requests, but then blocks and doesn't answer new requests. Probably a concurrency problem with greenlet.

frankie567 avatar Oct 18 '25 11:10 frankie567