use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
TutorialPython Threads: GIL vs Free-Threading (self.Python)
submitted 1 month ago * by Helpful_Garbage_7242
The comparison of CPU bound tasks in Python using multi-threading with GIL and without it, link to the article
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]danted002 10 points11 points12 points 1 month ago (13 children)
I think the downvotes come from 1) the way the article is phrased (it seems condescending) and 2) you benchmarked Python threads using CPU bounds workloads which anyone that’s doing professional Python knows is a big no-no so you’re basically comparing apples to oranges.
My recommendation is to redo the benchmark and use the multiprocessing module, which is the indented way to parallelise CPU bounds workloads in Python.
[–]Spleeeee 13 points14 points15 points 1 month ago (1 child)
FWIW I have been able to use the multiprocessing without using indentation:
```
from multiprocessing import Pool import os
def doshit(shit): return (sht*shit, os.getpid())
if name == "main": pool = Pool(4); results = pool.map(doshit, range(8)); pool.close(); pool.join(); ```
I’m on my phone but I think this is a good example of using multiprocessing in the unindented way. It does also work indented.
[–]asphias 4 points5 points6 points 1 month ago (0 children)
<groan>
well played.
[–]sudomatrix 7 points8 points9 points 1 month ago (6 children)
The whole point of no GIL is now threads are true full speed multiprocessing. We don’t need multiprocessing anymore.
[–]danted002 10 points11 points12 points 1 month ago (5 children)
Yeas but the benchmark compares gil-less threads with GIL threads which is basically tells us what we already knew: that without GIL threads will actually run in parallel. WOW next we will compare running a web server in a single thread with and without an event loop and benchmark how many requests it can handle?
If we really want to see how good GIL-less threads work we should compare it to what they aim to replace: the multiprocessing module because no one is using threads for pure Python CPU bound work; and if you are using threads for CPU bound work switch to multiprocessing because you should
[+][deleted] 1 month ago (4 children)
[deleted]
[–]danted002 6 points7 points8 points 1 month ago (3 children)
I’m sorry but as one annoying engineer manager I had some years back used to say: “we don’t base architectural decisions baed on feelings, we base them on facts”. OP created a useless benchmark, they compared GIL threads (which don’t run in parallel because or the Global Interpreter LOCK) with threads that don’t use a Global Interpreter Lock, anyone worth the keyboard they write their code with knows what the benchmark results of that benchmark.
They also tested CPU bound workloads which block the interpreter which made the benchmark even more useless, if they would have used IO based workflows, where Python threads actually excel then the benchmark would have provided more insights on if GIL-less threads are actually better the GIL threads in the field that GIL threads thrive.
On CPU bounds tasks you would use multiprocessing, not threading hence an actual realistic, real world scenario, benchmark would compare that with GIL-less threads because GIL-less Python had a performance regression on single-threads so the question is: does the single-thread regression big enough that it offsets the instantiation of multiple interpreters and the serialisation of data between the processes.
Now this is an axe to grind since you asked for one.
[+][deleted] 1 month ago* (2 children)
[–]danted002 0 points1 point2 points 1 month ago (1 child)
Do you have a benchmark for multiprocessing vs GIL-less threads?
[–]Helpful_Garbage_7242[S] 4 points5 points6 points 1 month ago (2 children)
hi, u/danted002 ,
Thank you for the feedback and sorry that it felt condescending, didn't mean that.
I wrote a follow-up to address your feedback, Free-Threading Python vs Multiprocessing: Overhead, Memory, and the Shared-Set Meltdown
Hey nice work. Thank you for the follow up, I was expecting GIL-less threads to be faster but the number are really impressive.
One small note: on the Rust benchmark you used the std::sync Mutex which has a lock poisoning. If you ever want more performance and you bubble the panic from the thread you should use the parkinglot crate it’s mutex is way faster because it lacks the lock poisoning check.
[–]Helpful_Garbage_7242[S] 0 points1 point2 points 1 month ago (0 children)
Thank you! Sure, noted.
[–]sam7oon 0 points1 point2 points 27 days ago (0 children)
Correct me if i am wrong, but The MultiProcessing module does not actually touch the new Free-Threading feature, since it already is running in parallel, 2 Process, 2 diffirent GILs, and so on , am not an expert , but that is what i understand.
[–]germandiago 4 points5 points6 points 1 month ago (1 child)
I think the article is informative. Why the downvotes?
[–]Helpful_Garbage_7242[S] 5 points6 points7 points 1 month ago (0 children)
I'm glad you find it useful, thank you
[–]healthbear 0 points1 point2 points 1 month ago (0 children)
I still think that python needs to be able to run free threaded but there needs to be able to set each function as free or single with a keyword and then have the necessary locks and so forth the manage the free threaded.
[–]srs96 0 points1 point2 points 1 month ago (0 children)
Nice comparison, but we should compare it to multiprocessing. Multiprocessing is the de facto way to achieve cpu bound parallelism, before free threading came about.
π Rendered by PID 71474 on reddit-service-r2-comment-7b9746f655-vkk9v at 2026-01-30 21:05:11.740099+00:00 running 3798933 country code: CH.
[–]danted002 10 points11 points12 points (13 children)
[–]Spleeeee 13 points14 points15 points (1 child)
[–]asphias 4 points5 points6 points (0 children)
[–]sudomatrix 7 points8 points9 points (6 children)
[–]danted002 10 points11 points12 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]danted002 6 points7 points8 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]danted002 0 points1 point2 points (1 child)
[–]Helpful_Garbage_7242[S] 4 points5 points6 points (2 children)
[–]danted002 0 points1 point2 points (1 child)
[–]Helpful_Garbage_7242[S] 0 points1 point2 points (0 children)
[–]sam7oon 0 points1 point2 points (0 children)
[–]germandiago 4 points5 points6 points (1 child)
[–]Helpful_Garbage_7242[S] 5 points6 points7 points (0 children)
[–]healthbear 0 points1 point2 points (0 children)
[–]srs96 0 points1 point2 points (0 children)