r/Python • u/NeuralLB-Lovro • 15h ago
Discussion Anyone running free-threaded Python 3.14 in production yet? Curious what actually breaks
Been testing the free-threaded build (3.14t) on some CPU-bound data processing work. The multi-core story is finally real after 30 years of GIL, but the friction is exactly what you'd expect: a couple of C-extension-heavy libs in my stack silently re-enable the GIL, and there's no clean way to detect that at runtime besides checking sys._is_gil_enabled() manually.
For anyone who's shipped something on 3.14t, not just benchmarked it:
What broke that you didn't expect?
Real speedups outside toy examples, or mostly marginal so far?
Prod yet, or still just kicking the tires?
Not fishing for a benchmark war. Genuinely curious what breaks in messy real codebases vs clean demos.
63
u/nathan12343 15h ago
You can set PYTHON_GIL=0 to force the GIL to remain off even if you import an extension that doesn’t support free-threading yet.
Are there specific open source projects you’re having trouble with?
I’ve been working on community support for free-threaded Python for a couple years now. Specific feedback about pain points from people who are experimenting with free-threading are valuable.
6
u/KingBardan 7h ago edited 2h ago
Edit Tldr:
- Many libs like torch requires global state.
- Free threading doesn't solve a lot that multiprocessing don't
- Free threading introduces new ways to cause data race.
- Free threading slows down normal code.
Many libraries use global state a lot and is not thread safe e.g. torch. For their context managers (which is widely used in other libs as well) So that disqualify any serious deep learning projects depending on torch to use free threading.
My opinion on free threading since you asked about pain point:
I much prefer ability to use context managers to free threading if using it makes the code cleaner
Free threading also slows down sequential code last time I checked
Multiprocessing is fast enough unless I'm dealing with web servers, at which I'll use async probably or gevent or another library that deals with this issue
7
u/nathan12343 5h ago
Thanks for your feedback. Hopefully this time next year we’ll be in a better spot. PyTorch is definitely on our radar as a pain point right now.
I much prefer ability to use context managers to free threading if using it makes the code cleaner
I don’t understand this. Context managers and free-threading are orthogonal. You can use context managers on the free-threaded build.
5
u/thisismyfavoritename 5h ago
i think that person might be talking about the pytorch context manager. Then again, not sure why you'd want to use free threading if it's GPU compute heavy
3
u/nathan12343 4h ago edited 3h ago
So I think what they were alluding to is this behavior:
with torch.no_grad(): with ThreadPoolExecutor() as ex: # grad is still ON in workers! results = list(ex.map(model, batches))Ideally (IMO) PyTorch would store the state for this sort of thing in a context variable. Right now it's stored in a thread local, which needs to be initialized explicitly in each thread. This is definitely something I can try to push on...
1
u/KingBardan 3h ago
Context variable is no go for torch, which is not pure python. Lots of stuff in it is tied to C things also device which is global.
Also I replied here
https://www.reddit.com/r/Python/comments/1v3ayph/comment/oz5xu50/
1
u/KingBardan 3h ago edited 2h ago
No not just torch, any context manager.
Simply using torch as an example because I just read its source code extensively couple months ago
My other comment
https://www.reddit.com/r/Python/comments/1v3ayph/comment/oz5xu50/
Not sure why you would use free threading...
Precisely. no hate to the developers, but free-threading doesn't unlock a lot for python but introduces yet other issues that needs to be dealt with
Also I understand it, tree threading is such a pain to maintains in cpython like thousands of macros or something last time I read the news
1
u/KingBardan 3h ago edited 3h ago
Context manager works by mutating context i.e. global / nonlocal state, right?
So it doesn't work without mutated global state, the number one cause for data race.
In multi-processing, which was the preferred way of doing things in parallel, global state is forked and exists per process.
This issue is not exclusive to free threading but multithreading in general, but freethreading only augments multi threading which is why my comment is the way it is
You can use contact manager on free threading
That is right. Now writing a python package would have to account for a different failure mode which is thread access, which, imo, is a very niche use case for python, at the cost of everything else.
2
u/ThatGuyWithAces 6h ago
PyTorch has experimental support for 3.14t since 2.10 I believe. Not disagreeing or anything, just throwing it out there.
1
u/KingBardan 6h ago
Sure it may support the build, but key features like torch dispatch mode (the reason that there's a 2.0 version of torch) assumes a sequential execution with their mode stack. I.e. not thread safe.
And the same pattern is everywhere in torch last time I checked (it was 3 months ago)
32
u/wRAR_ 13h ago
What are you selling?
36
u/nickcash 12h ago
A bunch of vibecoded todo-list-esque apps and ai consulting, whatever that is
Not sure why you're getting downvotes, the ai bros are always selling something
33
u/artofthenunchaku 6h ago
I build custom LLM integrations, RAG pipelines, and AI-powered applications for startups and businesses that need serious technical execution — not templates, not no-code, not hype.
I'm tired, boss
12
u/LALLANAAAAAA 12h ago
I'm sure someone will helpfully drop a link to their bullshit in the comments
Reddit is dead imo
9
3
u/Competitive_Travel16 4h ago edited 4h ago
I'm extremely happy with Flask performance using 3.14t as opposed to monkeypatching gevent. It used to be that getting the most out of Gunicorn/Flask when doing heavy I/O or background work meant relying on gevent and monkey-patching the Python standard library. It worked okay, but it came with its own set of brittle, import-order-dependent bugs (like silent hangs or deep recursion errors in modules like psycopg2, ssl, or multiprocessing).
Now that Python 3.14t is a free-threading (No-GIL) build, you get actual OS-level thread concurrency that scales across CPU cores without the fragility of monkey-patching.
Here is the setup we used to need:
from gevent import monkey
monkey.patch_all()
from flask import Flask, request
import requests
app = Flask(__name__)
@app.route("/")
def index():
resp = requests.get(f"http://api.example.com") # takes time
return "Hi there! " + resp.text
And here is the simple new reality under Python 3.14t:
# After: True threading under Python 3.14t
from flask import Flask, request
import requests
app = Flask(__name__)
@app.route("/")
def index():
# requests uses standard blocking IO, which is now natively
# safe and non-blocking to other threads in the process
resp = requests.get(f"http://api.example.com") # takes time
return "Hi there! " + resp.text
You run this using Gunicorn with the standard gthread worker class (python3.14t -m gunicorn --worker-class gthread --threads 50 app:app), and it just works.
Depending on your workload, you can expect an outstanding speedup. In I/O bound tasks, gthread slightly edges out or directly matches gevent with significantly less overhead. However, in mixed or heavily CPU-bound endpoint tasks, Python 3.14t enables multi-core execution per worker process, resulting in upwards of 2x to 4x performance multipliers by fully utilizing modern server architectures without the overhead of heavy multiprocessing process forks. True parallelism is here.
1
u/riksi 4h ago
In I/O bound tasks, gthread slightly edges out or directly matches gevent with significantly less overhead.
What? How would gthread have significant lower overhead when gevent was build specifically for lower memory overhead than threads & lower cpu by less context switching & mostly predictable switch-points.
1
u/Competitive_Travel16 3h ago
For purely I/O-bound tasks, gevent and its lightweight greenlets will still go toe-to-toe or slightly edge out threads due to cheaper context switching and lower memory footprints. However, the moment your endpoints perform mixed workloads or CPU-bound tasks (like JSON parsing, data transformation, or cryptography), Python 3.14t is better. It enables multi-core execution per worker process, allowing your OS threads to run in parallel. You get upwards of 2x to 4x performance multipliers.
39
u/LALLANAAAAAA 12h ago
Genuinely curious
yawn
Its kinda nuts that LLMs have billions and billions of dollars behind them and they all produce the same garbage tone and choose the same words every bloody time
Its also sad as hell that it's users are too lazy or too stupid to realize it and keep posting it
RIP reddit, it used to be kind of OK
28
u/Challseus 6h ago
"Genuinely curious"
This is indication of AI use? You had never heard this phrase prior to 2023?
Genuinely curiuous...
18
u/LALLANAAAAAA 5h ago
This is indicative of AI use?
When it comes at the end of multiple other tells, yes. Anyone paying a minimal amount of attention to the state of posts across any and all social media sites should be able to recognize LLM smell by this point.
here's a phrase search of the ClaudeAI sub to illustrate my point, but it's just one of many indicators.
Some other tells are over-reliance on unordered lists, short punchy sentences, and repeated point / counterpoint sentences (This, or that?), frequently but not always in the format of rhetorical negation (That's not X, it's Y) or in this case, "I'm not doing this, I'm doing that."
They also love beginning / middle / end structure.
There's also words they can't seem to avoid in software contexts, like ship / shipped / silently failing / friction. Other examples would be "load bearing", "sit with", or their favorite, "the [...] part? Blah blah blah". The hard part, the surprising part, the annoying part. The extremely annoying part.
So in this case, we have the tripartite structure, strong keyword usage, an unordered list of short punchy point / counterpoint sentences, "I'm not this, I'm that", and lastly they try to elicit engagement with "curious if anyone else" as the closer. It checks almost all the boxes.
So yeah. You can validate what I'm saying if you want, these are well documented tendencies of LLMs.
4
4
4
0
5
•
u/AutoModerator 11h ago
Your submission has been automatically queued for manual review by the moderation team because it has been reported too many times.
Please wait until the moderation team reviews your post.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.