News for hackers. Stuff that matters.
Re:Free-threaded CPython is ready to experiment with by phkahler on Friday July 12, 2024 @05:31PM (#40949637)
I feel like most things that will benefit from moving to multiple cores for performance should probably not be written in Python. OTH "most" is not "all" so it's gonna be awesome for some.
Re:Free-threaded CPython is ready to experiment with by wongarsu on Friday July 12, 2024 @07:09PM (#40950295)
I often reach for python multiprocessing for code that will run $singleDigit number of times but is annoyingly slow when run sequentially. I could never justify the additional development time for using a more performant language, but I can easily justify spending 5-10 minutes making the embarrassingly parallel stuff execute in parallel.
Re:Free-threaded CPython is ready to experiment with by throwaway81523 on Saturday July 13, 2024 @01:29AM (#40952003)
I've generally been able to deal with embarassing parallelism by just chopping up the input and running multiple processes with GNU Parallel. I haven't needed the multiprocessing module or free threading so far. I believe CPython still relies on various bytecodes to run atomically, which you get automatically with the GIL present. So I wonder if hard-to-reproduce concurrency bugs will keep surfacing in the free-threaded CPython for quite some time.

I feel like all of this is tragic and Python should have gone to a BEAM-like model some years ago, like as part of the 2 to 3 transition. Instead we get async wreckage and now free threading with its attendant hazards. Plus who knows how many C modules won't be expecting this.

Re:Free-threaded CPython is ready to experiment with by robertlagrant on Saturday July 13, 2024 @02:25AM (#40952230)
Async seems fine? What's wrong with it?
Re:Free-threaded CPython is ready to experiment with by throwaway81523 on Saturday July 13, 2024 @02:51AM (#40952317)
Watch this video and maybe you'll understand ;). Warning, NSFW (lots of swearing), use headphones.

https://www.youtube.com/watch?v=bzkRVzciAZg

This is also good:

https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...

web search on "colored functions" finds lots of commentary on that article.

Re:Free-threaded CPython is ready to experiment with by wesselbindt on Saturday July 13, 2024 @03:37AM (#40952485)
I've always found the criticism leveled by the colored functions blog post a bit contrived. Yes, when you replace the words async/await with meaningless concepts I do not care about, it's very annoying to have to arbitrarily mark a function as blue or red. But when you replace the word "aync" with something like "expensive", or "does network calls", it becomes clear that "async/await" makes intrinsic properties about your code (e.g., is it a bad idea to put this call in a loop from a performance perspective) explicit rather than implicit.

In short, "await" gives me an extra piece of data about the function, without having to read the body of the function (and the ones it calls, and the ones they call, etc). That's a good thing.

There are serious drawbacks to async/await, and the red/blue blog post manages to list none of them.

EDIT: all of the above is predicated on the idea that reading code is harder than writing it. If you believe the opposite, then blue/red has a point.

Re:Free-threaded CPython is ready to experiment with by adament on Saturday July 13, 2024 @04:16AM (#40952612)
But a synchronous function can and many do make network calls or write to files. It is a rather vague signal about the functions behavior as opposed to the lack of the IO monad in Haskell.

To me the difficulty is more with writing generic code and maintaining abstraction boundaries. Unless the language provides a way to generalise over asyncness of functions, we need a combinatorial explosion of async variants of generic functions. Consider a simple filter algorithm it needs versions for: (synchronous vs asynchronous iterator) times (synchronous vs asynchronous predicate). We end up with a pragmatic but ugly solution: provide 2 versions of each algorithm: an async and a sync, and force the user of the async one to wrap their synchronous arguments.

Similarly changing some implementation detail of a function might change it from a synchronous to an asynchronous function, and this change must now propagate through the entire call chain (or the function must start its own async runtime). Again we end up in a place where the most future proof promise to give for an abstraction barrier is to mark everything as async.

Re:Free-threaded CPython is ready to experiment with by wesselbindt on Saturday July 13, 2024 @06:11AM (#40953033)
> But a synchronous function can and many do make network calls or write to files

This, for me, is the main drawback of async/await, at least as it is implemented in for example Python. When you call a synchronous function which makes network calls, then it blocks the event loop, which is pretty disastrous, since for the duration of that call you lose all concurrency. And it's a fairly easy footgun to set off.

> It is a rather vague signal about the functions behavior as opposed to the lack of the IO monad in Haskell.

I'm happy you mentioned the IO monad! For me, in the languages people pay me to write in (which sadly does not include Haskell or F#), async/await functions as a poor man's IO monad.

> Again we end up in a place where the most future proof promise to give for an abstraction barrier is to mark everything as async.

Yes, this is one way to write async code. But to me this smells the same as writing every Haskell program as a giant do statement because the internals might want to do I/O at some point. Async/await makes changing side-effect free internals to effectful ones painful, which pushes you in the direction of doing the I/O at the boundaries of your system (where it belongs), rather than all over the place in your call stack. In a ports-adapters architecture, it's perfectly feasible to restrict network I/O to your service layer, and leave your domain entirely synchronous. E.g. sth like

  async def my_service_thing(request, database):
    my_business_object = await database.get(request.widget_id)
    my_business_object.change_state(request.new_widget_color)    # some complicated, entirely synchronous computation
    await database.save(my_business_object)
Async/await pushes you to code in a certain way that I believe makes a codebase more maintainable, in a way similar to the IO monad. And as with the IO monad, you can subvert this push by making everything async (or writing everything in a do statement), but there's better ways of working with them, and judging them based on this subversion is not entirely fair.

> ugly solution: provide 2 versions of each algorithm: an async and a sync

I see your point, and I think it's entirely valid. But having worked in a couple async codebases for a couple of years, the amount of stuff I (or one of my collaborators) have had to duplicate for this reason I think I can count on one hand. It seems that in practice this cost is a fairly low one.

Re:Free-threaded CPython is ready to experiment with by bjourne on Sunday July 14, 2024 @09:59AM (#40961018)
What you write is eerily similar to one of the pain points of Haskell. You can write a compiler that is purely functional. But then you want logging so you must put wrap it with the IO monad. And then also every function that calls the compiler and so on.
Re:Free-threaded CPython is ready to experiment with by pansa2 on Saturday July 13, 2024 @04:30AM (#40952654)
> when you replace the word "aync" with something like "expensive", or "does network calls", it becomes clear that "async/await" makes intrinsic properties about your code explicit rather than implicit.

Do you think we should be annotating functions with `expensive` and/or `networking`? And also annotating all of their callers, recursively? And maintaining 4 copies of every higher-order function depending on whether the functions it calls are `expensive`, `networking`, neither or both?

No, we rely on documentation for those things, and IMO we should for `async` as well. The reason we can’t, and why `async`/`await` exist, is because of shortcomings (lack of support for stackful coroutines) in language runtimes. The best solution is to fix those shortcomings, not add viral annotations everywhere.

Re:Free-threaded CPython is ready to experiment with by wesselbindt on Saturday July 13, 2024 @05:30AM (#40952865)
So here I think we differ fundamentally in how we like to read code. I much prefer being able to quickly figure out things of interest about a function by glancing at its signature, rather than look at documentation, or worse, having to read the implementation of the function and the functions it calls (and so on, recursively).

For example, I much prefer a signature like

  def f(a: int) -> str:
over

  def f(a):
because it allows me to see, without reading the implementation of the function (or, if it exists, and I'm willing to bet on its reliability, the documentation), that it takes an integer, and gives me a string. And yes, this requires that I write viral type annotations on all my functions when I write them, but for me the bottleneck at my job is not writing the code, it's reading it. So that's a small upfront cost I'm very much willing to pay.

> Do you think we should be annotating functions with `expensive` and/or `networking`? And also annotating all of their callers, recursively?

Yes, absolutely, and yes, absolutely. That's just being upfront and honest about an intrinsic property of those functions. A function calling a function that does network I/O by transitivity also does network I/O. I prefer code that's explicit over code that's implicit.

Re:Free-threaded CPython is ready to experiment with by pansa2 on Saturday July 13, 2024 @05:57AM (#40952975)
> Yes, absolutely, and yes, absolutely.

Fair enough, that's a valid philosophy, and one in which `async`/`await` makes perfect sense.

However, it's not Python's philosophy - a language with dynamic types, unchecked exceptions, and racy multithreading. In Python, `async`/`await` seems to be at odds with other language features - it feels like it's more at home in a language like Rust.

Re:Free-threaded CPython is ready to experiment with by wesselbindt on Saturday July 13, 2024 @06:21AM (#40953082)
I completely agree with you. However I've always found the dynamic typing approach to be a bit at odds with

  python3 -c "import this" | head -4 | tail -1
I think the fast and loose style that Python enables is perfect for small scripts and one off data science notebooks and the like. But having worked in large codebases which adopt the same style, and ones that avoid it through static typing and in some cases async/await, the difference in productivity I've noticed in both me and my collaborators is too stark for me to ignore.

I think I should've been more nuanced in my comments praising async/await. I believe that what I say is valid in large IO-bound applications which go beyond basic CRUD operations. In general it depends, of course.

Re:Free-threaded CPython is ready to experiment with by pansa2 on Saturday July 13, 2024 @06:43AM (#40953195)
> I think the fast and loose style that Python enables is perfect for small scripts and one off data science notebooks and the like.

Agreed - I only use Python for scripts like this, preferring statically-typed, AOT-compiled languages for larger programs.

That’s why I think Python should have adopted full coroutines - it should play to its strengths and stick to its fast-and-loose style. However, the people who decide how the language evolves are all employees of large companies using it for large codebases - their needs are very different from people who are only using Python for small scripts.

Re:Free-threaded CPython is ready to experiment with by hiddew on Saturday July 13, 2024 @04:38AM (#40952672)
> The reason we can’t, and why `async`/`await` exist, is because of shortcomings (lack of support for stackful coroutines) in language runtimes

The JVM runtime has solved this problem neatly with virtual threads in my opinion. Run a web request in a virtual thread, and all blocking I/O is suddenly no longer blocking the OS thread, but yielding/suspending and giving and giving another virtual thread run time. And all that without language keywords that go viral through your program.

Re:Free-threaded CPython is ready to experiment with by pansa2 on Saturday July 13, 2024 @04:48AM (#40952702)
Yes, this is similar to how Go works. IIRC the same approach was available in Python as a library, “greenlet”, but Python’s core developers rejected it in favour of `async`/`await`.
Re:Free-threaded CPython is ready to experiment with by throwaway81523 on Saturday July 13, 2024 @02:49PM (#40956004)
The Python community seems to have a virulent hatred of threads. I don't understand the reason. Yes there are hazards but you can code in a style that avoids them. With something like BEAM you can even enforce the style. Async/await of course introduce their own hazards.
Re:Free-threaded CPython is ready to experiment with by kaba0 on Sunday July 14, 2024 @01:40PM (#40962227)
I think it wouldn’t work as nicely with python, which deeply builds on C FFI. Java has a different history, and almost the whole ecosystem is pure, making it able to take advantage of it.
Re:Free-threaded CPython is ready to experiment with by robertlagrant on Monday July 15, 2024 @04:51AM (#40966228)
There's no hatred. There are just lots of libraries that can't be multithreaded, due to historical reasons. This is being worked on right now[0], though.

[0] https://peps.python.org/pep-0703

Re:Free-threaded CPython is ready to experiment with by throwaway81523 on Monday July 15, 2024 @09:23PM (#40972932)
The GIL only gets in the way of parallelism. Yes there is real hatred. You can experience it if you visit #python on libera and ask anything about threads. "Aieee! The non-determinism! The race conditions! Etc." Of course the async requires an async version of the whole i/o system, it can block on long computations or the wrong system calls, etc. And many rock solid systems are written in Erlang, which uses preemptive lightweight processes for all its concurrency needs.

Lots of microcontroller OS's use cooperative multitasking but once there are enough machine resource's, OS's generally become preemptive. Async concurrency is basically cooperative multitasking with similar issues. Does Python give a way to open a file asynchronously in Linux? It's now possible with io_uring but it was impossible for a very long time (like decades). Erlang and GHC both use thread pools to deal with that. The use the old synchronous open(2) call but move it into an auxiliary thread so it won't block the calling thread.

Re:Free-threaded CPython is ready to experiment with by robertlagrant on Tuesday July 16, 2024 @04:36AM (#40974623)
> "Aieee! The non-determinism! The race conditions! Etc."

That doesn't sound like real hatred. Those sound like real concerns, which need to be addressed, and the attempt to remove the GIL is doing so very much with those concerns in mind.

Re:Free-threaded CPython is ready to experiment with by gpderetta on Saturday July 13, 2024 @06:00AM (#40952983)
Except that at least in python async doesn't mean that. Non async functions can do networking, block, or do expensive operations.

On the other hand async functions can be very cheap.

Again, which useful property does async protect?

Re:Free-threaded CPython is ready to experiment with by robertlagrant on Monday July 15, 2024 @04:53AM (#40966242)
Yeah gotcha - I'm familiar with the colored functions argument. I see the conceptual downside, but it doesn't seem that bad in practice. I have a pre-commit hook that shouts at me if I call an async function synchronously.
Re:Free-threaded CPython is ready to experiment with by fuzztester on Friday July 12, 2024 @07:42PM (#40950477)
>I feel like most things that will benefit from moving to multiple cores for performance should probably not be written in Python.

I feel like most things that will benefit from performance should probably not be written in Python.

Re:Free-threaded CPython is ready to experiment with by fuzztester on Friday July 12, 2024 @07:44PM (#40950490)
Re:Free-threaded CPython is ready to experiment with by fuzztester on Friday July 12, 2024 @09:55PM (#40951145)
wonder if the fearful and ignorant downvoter knows that python is one of the slower among the dynamic languages, forget about the static languages, which are a hell of a lot faster. e.g. perl, which a lot of stupid ignorant hners deride, is a lot faster than python, orders of magnitudes faster.

the guy is probably suffering from the Upton Sinclair effect:

https://en.m.wikipedia.org/wiki/Upton_Sinclair

He is also well remembered for the quote: "It is difficult to get a man to understand something, when his salary depends upon his not understanding it."[4]

same thing applies here.

Re:Free-threaded CPython is ready to experiment with by jacob019 on Friday July 12, 2024 @10:13PM (#40951226)
It's very unpopular to mention Perl, but I did many cool things with it back in the day, and it still holds a special place for me. Perl taught me the power of regex--it's really first class in Perl. I still have some Perl code in production today. But to be fair, it is really easy to write spaghetti in Perl if you don't know what you're doing.
Re:Free-threaded CPython is ready to experiment with by fuzztester on Saturday July 13, 2024 @01:52AM (#40952091)
don't worry about unpopularity, bro. worry about being true. the rest will take care of itself. if not, you are in the wrong company, forum, or place, and better to work on getting out of there.
Re:Free-threaded CPython is ready to experiment with by fuzztester on Sunday July 14, 2024 @08:15PM (#40964278)
> But to be fair, it is really easy to write spaghetti in Perl if you don't know what you're doing.

bro, you really need to educate yourself some more, if you say things like that.

baloney!

first of all, perl is already spaghetti. I mean, it has all those curlicues, aka sigils. perl devs love it that way.

second of all, that point about being able to write spaghetti is not unique to perl.

many people do it in many languages.

in fact it is common here on hn to see the statement "you can write fortran in any language".

Re:Free-threaded CPython is ready to experiment with by saagarjha on Friday July 12, 2024 @11:56PM (#40951658)
They’re probably downvoting you because you’ve posted like the laziest trope comment there is. lol Python slow everyone is paid to hide the truth amirite
Re:Free-threaded CPython is ready to experiment with by fuzztester on Saturday July 13, 2024 @01:39AM (#40952046)
thanks for your viewpoint, but i doubt it. one of them (user jacob019) talked about the "need" to be tactful (in a thread about software, aka logic !!!) and the same guy tried to divert the topic to perl, in another comment. I'm damn sure it's the upton sinclair syndrome at work, as I posted, also in this subthread, i.e. they are lying because of vested interests, like salary. another way of describing it is "The emperor's new clothes", that well known fable about hypocrisy and sycophancy for gain.
Re:Free-threaded CPython is ready to experiment with by porksoda on Saturday July 13, 2024 @06:27AM (#40953115)
Your comments feel like you want a reddit style battle of wits. You throw words like ignorant around rather freely. I downvote these comments because they lower the tone of the discussion. We're not here to talk about each other or feel smarter than others.. Well I'm not.
Re:Free-threaded CPython is ready to experiment with by fuzztester on Sunday July 14, 2024 @08:36PM (#40964377)
I don't give a flying fuck about your feelings or your opinions about my comments, just as you should not about mine. i am a free man. you should try to be one too. we can talk to each other, but that does not mean that either of us has to believe or be convinced by what the other person says. is this not fuckingly blindlingly obvious to you?

if not, you have a serious perception problem.

yes, I do throw around words, just like anyone else, but not freely, instead, I do that after at least some thought, which I do not see happening in the people whom I replied to, nor in your comment above.

Re:Free-threaded CPython is ready to experiment with by fuzztester on Sunday July 14, 2024 @08:44PM (#40964417)
why not, ffs? particularly when the person insults you? are you a sissy?
Re:Free-threaded CPython is ready to experiment with by dr_kiszonka on Saturday July 13, 2024 @12:43AM (#40951824)
One day your ISP emails you that they increased your upload and download speeds. Sweet, right? Same here with Python.
Re:Free-threaded CPython is ready to experiment with by fuzztester on Saturday July 13, 2024 @01:00AM (#40951883)
sweet? no, bitter. 'cause you're moving goalposts, ha ha. utterly flawed logic, bro, on a site which is about software, so about logic. but you know it, don't you? so stop trying to con me. ain't gonna work.

as I said in this thread, see the Upton Sinclair quote.

getting a speed improvement is fine but not the same thing as being slow in the first place, like python is. don't pretend you don't know it. or if you don't, you have no business talking.

kthxbye ;)

why so much deliberate fakery on hn? i know. upton sinclair again.

Re:Free-threaded CPython is ready to experiment with by fuzztester on Saturday July 13, 2024 @01:54AM (#40952096)
Re:Free-threaded CPython is ready to experiment with by fuzztester on Friday July 12, 2024 @09:58PM (#40951161)
hee hee hee, downvoters, showing your lack of calibre, hee hee hee.

see here:

https://news.ycombinator.com/item?id=40951145

Re:Free-threaded CPython is ready to experiment with by jacob019 on Friday July 12, 2024 @10:19PM (#40951256)
Bashing Python in Python development thread is not tactful.
Re:Free-threaded CPython is ready to experiment with by fuzztester on Saturday July 13, 2024 @01:11AM (#40951922)
it may not be tactful but it sure is factful (even if that last word is ungrammatical, at least the sentence is poetical). he he he.

jfc. guido knows ;), this thread is getting weirder and weirder, creepier and creepier.

are you literally implying that I should lie about known facts about python slowness?

"tactful" my foot.

then I guess the creators of PyPy and Unladen Swallow (the latter project was by Google) were/are not being tactful either, because those were two very prominent projects to speed up Python, in other words, to reduce its very well known slowness.

There is/was also Cython and Pyston (the latter at Dropbox, where Guido (GvR, Python creator) worked for a while. Those were or are also projects to speed up Python program execution.

https://en.m.wikipedia.org/wiki/PyPy

https://peps.python.org/pep-3146/

Excerpt from the section titled "Rationale, Implementation" from the above link (italics mine):

[

Many companies and individuals would like Python to be faster, to enable its use in more projects. Google is one such company.

Unladen Swallow is a Google-sponsored branch of CPython, initiated to improve the performance of Google’s numerous Python libraries, tools and applications. To make the adoption of Unladen Swallow as easy as possible, the project initially aimed at four goals:

    A performance improvement of 5x over the baseline of CPython 2.6.4 for single-threaded code.
    100% source compatibility with valid CPython 2.6 applications.
    100% source compatibility with valid CPython 2.6 C extension modules.
    Design for eventual merger back into CPython.
]

Your honor, I rest my case.

Re:Free-threaded CPython is ready to experiment with by fuzztester on Saturday July 13, 2024 @01:57AM (#40952114)
if Google wanted a performance increase of 5x over the then existing python, I guess we can safely say that Python was slow, amirite. and yes, I know the version number mentioned, and what it is today.
Re:Free-threaded CPython is ready to experiment with by jacob019 on Saturday July 13, 2024 @01:44PM (#40955533)
tactful - showing skill and sensitivity in dealing with people. Right or wrong, your comments do not contribute to the discussion. Open source development is about collaboration. Your irrelevant comments are disrespectful to all the hard working developers who have been working together to push the limits of what is possible with what may be the most widely used programming language of our time. I use Python for it's ergonomics and community, not for speed. Removing the GIL has been something we've been yearning for since the Python 2 days. And the speed has improved drastically in recent years with each release. You don't win a prize for being right.
Re:Free-threaded CPython is ready to experiment with by fuzztester on Wednesday July 17, 2024 @09:43PM (#40991804)
>tactful - showing skill and sensitivity in dealing with people. Right or wrong, your comments do not contribute to the discussion.

just take a look at the depth of your incredibly rotten stupidity and ugliness of mind, you fucktard and dotard (dotard means something like a senile person, in case you didn't know):

hn user jacob019, you little mofo:

you say that "Right or wrong, your comments do not contribute to the discussion."

that itself is a contradiction in terms.

so you are saying that my comments do not contribute to the discussion even if i am right?

(what an utter fool and liar and swine you are.)

then why should i and anyone else think that your comments contribute to the discussion when they so totally fucking wrong, biased, shitheaded, pissheaded, and other choice epithets?

comgrats, you have really jumped the shark in terms of being a creep.

enjoy your miserable life for what it is worth, you worm.

Re:Free-threaded CPython is ready to experiment with by jacob019 on Monday July 22, 2024 @05:43PM (#41040133)
Seems I hit a nerve. We never stop growing. Good luck to you friend.
[dead]
Re:Free-threaded CPython is ready to experiment with by geertj on Saturday July 13, 2024 @01:38AM (#40952038)
You might be getting downvoted because many people know Python is among the slower dynamic languages, and there are other reasons to use it. Speaking for myself, the reasons that make me reach for Python for some projects are the speed of development, large ecosystem of libraries, large developer pool, and pretty good tooling/IDE support.
Re:Free-threaded CPython is ready to experiment with by fuzztester on Saturday July 13, 2024 @02:03AM (#40952142)
then it would be much preferable if they said so explicitly, although both of those are points I already know well. both are common knowledge, not just the first, i e. the slowness. the productivity and other benefits are common knowledge too.

downvoting is such a fucking dumb way of disagreeing. how does one know whether the downvote is because a person disapproves of or dislikes what one said or because they think what one said is wrong. no way to know. amirite? :)

Re:Free-threaded CPython is ready to experiment with by DanielVZ on Friday July 12, 2024 @06:15PM (#40949956)
Usually performance critical code is written in cpp, fortran, etc, and then wrapped in libraries for Python. Python still has a use case for glue code.
Re:Free-threaded CPython is ready to experiment with by andmkl on Friday July 12, 2024 @08:22PM (#40950681)
Yes, but then extensions can already release the GIL and use the simple and industrial strength std::thread, which is orders of magnitude easier to debug.
Re:Free-threaded CPython is ready to experiment with by woodruffw on Friday July 12, 2024 @08:52PM (#40950852)
Concurrent operations exist at all levels of the software stack. Just because native extensions might want to release the GIL and use OS threads doesn't mean pure Python can't also want (or need) that.

(And as a side note: I have never, in around a decade of writing C++, heard std::thread described as "easy to debug.")

Re:Free-threaded CPython is ready to experiment with by ipsod on Friday July 12, 2024 @08:54PM (#40950861)
Really? Cool.

I expected that dropping down to C/C++ would be a large jump in difficulty and quantity of code, but I've found it isn't, and the dev experience isn't entirely worse, as, for example, in-editor code-intelligence is rock solid and very fast in every corner of my code and the libraries I'm using.

If anyone could benefit from speeding up some Python code, I'd highly recommend installing cppyy and giving it a try.

Re:Free-threaded CPython is ready to experiment with by woodson on Friday July 12, 2024 @09:22PM (#40951004)
Thanks, I haven’t come across cppyy! But I’ve worked with pybind11, which works well, too.
Re:Free-threaded CPython is ready to experiment with by ipsod on Friday July 12, 2024 @11:08PM (#40951462)
Sure! I tried pybind11, and some other things. cppyy was the first I tried that didn't give me any trouble. I've been using it pretty heavily for about a year, and still no trouble.
Re:Free-threaded CPython is ready to experiment with by nly on Saturday July 13, 2024 @05:19AM (#40952819)
Last I checked cppyy didn't build any code with optimisations enabled (same as cling)
Re:Free-threaded CPython is ready to experiment with by ipsod on Saturday July 13, 2024 @12:17PM (#40954901)
It seems like you might be able to enable some optimizations with EXTRA_CLING_ARGS. Since it's based on cling, it's probably subject to whatever limitations cling has.

To be honest, I don't know much about the speed, as my use-case isn't speeding up slow code.

Re:Free-threaded CPython is ready to experiment with by MBCook on Friday July 12, 2024 @06:09PM (#40949913)
But it would give you more headroom before rewriting for performance would make sense right? That alone could be beneficial to a lot of people.
Re:Free-threaded CPython is ready to experiment with by rty32 on Friday July 12, 2024 @07:27PM (#40950403)
I think it is beneficial to some people, but not a lot. My guess is that most Python users (from beginners to advanced users, including many professional data scientists) have never heard of GIL or thought of doing any parallelization in Python. Code that needs performance and would benefit from multithreading, usually written by professional software engineers, likely isn't written in Python in the first place. It would make sense for projects that can benefit from disabling GIL without a ton of changes. Remember it is not trivial to update single threaded code to use multithreading correctly.

in Python language specifically. Their library may have already done some form of parallelization under the hood

Re:Free-threaded CPython is ready to experiment with by bdd8f1df777b on Saturday July 13, 2024 @12:09AM (#40951702)
> Code that needs performance and would benefit from multithreading, usually written by professional software engineers, likely isn't written in Python in the first place.

There are a lot of simple cases where multi-threading can easily triple or quadruple the performance.

Re:Free-threaded CPython is ready to experiment with by Certhas on Saturday July 13, 2024 @08:14AM (#40953626)
But multiprocessing can't?

I used to write a ton of MPI based parallel python. It's pretty straightforward. But one could easily imagine trying to improve the multiprocessing ergonomics rather than introducing threading. Obviously the people who made the choice to push forward with this are aware of these options, too. Still mildly puzzling to me why threads for Python are needed/reasonable.

Re:Free-threaded CPython is ready to experiment with by pdhborges on Saturday July 13, 2024 @04:48PM (#40956764)
It doesn't to be puzzling just read the motivation section of https://peps.python.org/pep-0703/
Re:Free-threaded CPython is ready to experiment with by Certhas on Sunday July 14, 2024 @09:03AM (#40960719)
I know that document. It doesn't really answer this point though. It motivates the need for parallelism in slow python by noting that this is important once other performance critical code is in extensions.

But the mai point against multiprocessing seems to be that spawning new processes is slow ...

That single "alternatives" paragraph doesn't answer at all why mp isn't viable for python level parallelism.

I am no longer invested in python heavily, I am sure there are discussions or documents somewhere that go into this more. Might be that it's simply that everyone is used to threads so you should support it for sheer familiarity. All I am saying is it's not obvious to a casual observer.

Re:Free-threaded CPython is ready to experiment with by bdd8f1df777b on Friday July 19, 2024 @09:53AM (#41006617)
A common pain point for me is parallel data loading and processing for PyTorch or TensorFlow. Multiprocessing has a lot of bugs and pain points to deal with when doing ML. Examples: https://github.com/search?q=repo%3Apytorch%2Fpytorch+multipr.... Most of these issues do not exist in a multithreading world, because resource sharing is trivial in that case.

Since Python leads over any other languages in the ML community, and ML is a hot topic right now, it makes sense for Python developers to secure the lead by making the life of ML developers easier, which is by introducing GIL-less multi-threading.

Re:Free-threaded CPython is ready to experiment with by eigenvalue on Friday July 12, 2024 @08:26PM (#40950703)
I personally optimize more for development time and overall productivity in creating and refactoring, adding new features, etc. I'm just so much faster using Python than anything else, it's not even close. There is such an incredible world of great libraries easily available on pip for one thing.

Also, I've found that ChatGPT/Claude3.5 are much, much smarter and better at Python than they are at C++ or Rust. I can usually get code that works basically the first or second time with Python, but very rarely can do that using those more performant languages. That's increasingly a huge concern for me as I use these AI tools to speed up my own development efforts very dramatically. Computers are so fast already anyway that the ceiling for optimization of network oriented software that can be done in a mostly async way in Python is already pretty compelling, so then it just comes back again to developer productivity, at least for my purposes.

Re:Free-threaded CPython is ready to experiment with by indigodaddy on Friday July 12, 2024 @09:55PM (#40951139)
Ever messed about with Claude and php?
Re:Free-threaded CPython is ready to experiment with by lanstin on Friday July 12, 2024 @10:01PM (#40951174)
I don't think we are supposed to use HN for humor only posts.
Re:Free-threaded CPython is ready to experiment with by saagarjha on Friday July 12, 2024 @10:58PM (#40951417)
You think wrong
Re:Free-threaded CPython is ready to experiment with by jacob019 on Friday July 12, 2024 @10:08PM (#40951206)
lol
Re:Free-threaded CPython is ready to experiment with by indigodaddy on Saturday July 13, 2024 @10:46AM (#40954420)
Why the downvotes? Totally serious question. Jesus Christ HN
Re:Free-threaded CPython is ready to experiment with by goosejuice on Saturday July 13, 2024 @01:45AM (#40952068)
Kind of sounds like you are optimizing for convenience :)
Re:Free-threaded CPython is ready to experiment with by jodrellblank on Friday July 12, 2024 @11:01PM (#40951432)
https://www.servethehome.com/wp-content/uploads/2023/01/Inte...

AMD EPYC 9754 with 128-cores/256-threads, and EPYC 9734 with 112-cores/224-threads. TomsHardware says they "will compete with Intel's 144-core Sierra Forest chips, which mark the debut of Intel's Efficiency cores (E-cores) in its Xeon data center lineup, and Ampre's 192-core AmpereOne processors".

What in 5 years? 10? 20? How long will "1 core should be enough for anyone using Python" stand?

Re:Free-threaded CPython is ready to experiment with by d0mine on Saturday July 13, 2024 @12:02AM (#40951682)
Number crunching code in Python (such as using numpy/pytorch) performs the vast vast majority of its calculations in C/Fortran code under the hood where GIL can be released. Single python process can use multiple CPUs.

There is code that may benefit from the free threaded implementation but it is not as often as it might appear and it is not without its own downsides. In general, GIL simplifies multithreaded code.

There were no-GIL Python implementations such as Jython, IronPython. They hadn't replaced CPython, Pypy implementation which use GIL i.e., other concerns dominate.

Re:Free-threaded CPython is ready to experiment with by imachine1980_ on Saturday July 13, 2024 @01:28AM (#40951999)
Yes but jython am iron aren't the standard, and I feel the more relevant part is inertia, puppy is design whit lots of concern of compatibility, then being the new standard can totally make difference making both cases not a good comparison.
Re:Free-threaded CPython is ready to experiment with by phkahler on Tuesday July 16, 2024 @11:33AM (#40977503)
>> What in 5 years? 10? 20? How long will "1 core should be enough for anyone using Python" stand?

If you're looking for a 32x or 128x performance improvement from python supporting multi-core you should probably rewrite in C, C++, Rust, or Fortran and get that 100x improvement today on a single core. If done properly you can then ALSO get the gain from multiple cores on top of that. Or to put it another way, if performance is critical python is a poor choice.

Re:Free-threaded CPython is ready to experiment with by jodrellblank on Thursday July 18, 2024 @10:14PM (#41001547)
"instead of taking advantage of hardware you own, you should do a LOT of work in a language you don't know" - how is that in any way a reasonable suggestion or alternative?

> "Or to put it another way, if performance is critical python is a poor choice."

To put it another way, just because performance isn't critical, doesn't mean that more performance for free is not desirable or beneficial, or that ignoring 127/128ths of available performance is fine.

Re:Free-threaded CPython is ready to experiment with by Derbasti on Friday July 12, 2024 @11:42PM (#40951592)
A thought experiment:

A piece of code takes 6h to develop in C++, and 1h to run.

The same algorithm takes 3h to code in Python, but 6h to run.

If I could thread-spam that Python code on my 24 core machine, going Python would make sense. I've certainly been in such situations a few times.

Re:Free-threaded CPython is ready to experiment with by Certhas on Saturday July 13, 2024 @05:57AM (#40952974)
C++ and python are not the only options though.

Julia is one that is gaining a lot of use in academia, but any number of modern, garbage collected compiled high level languages could probably do.

Re:Free-threaded CPython is ready to experiment with by rbanffy on Saturday July 13, 2024 @06:02PM (#40957227)
Fair. Add a couple hours to learn enough Julia to write the code.
Re:Free-threaded CPython is ready to experiment with by tho34234234 on Saturday July 13, 2024 @12:35AM (#40951796)
It's not just about "raw-flop performance" though; it affects even basic things like creating data-loaders that run in the background while your main thread is doing some hard ML crunching.

Every DL library comes with its own C++ backend that does this for now, but it's annoyingly inflexible. And dealing with GIL is a nightmare if you're dealing with mixed Python code.

Re:Free-threaded CPython is ready to experiment with by jillesvangurp on Saturday July 13, 2024 @12:54AM (#40951861)
Right now you are right. This is about taking away that argument. There's no technical reason for this to stay true. Other than that the process of fixing this is a lot of work of course. But now that the work has started, it's probably going to progress pretty steadily.

It will be interesting to see how this goes over the next few years. My guess is that a lot of lessons were learned from the python 2 to 3 move. This plan seems pretty solid.

And of course there's a relatively easy fix for code that can't work without a GIL: just do what people are doing today and just don't fork any threads in python. It's kind of pointless in any case with the GIL in place so not a lot of code actually depends on threads in python.

Preventing the forking of threads in the presence of things still requiring the GIL sounds like a good plan. This is a bit of meta data that you could build into packages. This plan is actually proposing keeping track of what packages work without a GIL. So, that should keep people safe enough if dependency tools are updated to make use of this meta data and actively stop people from adding thread unsafe packages when threading is used.

So, I have good hopes that this is going to be a much smoother transition than python 2 to 3. The initial phase is probably going to flush out a lot of packages that need fixing. But once those fixes start coming in, it's probably going to be straightforward to move forward.

Re:Free-threaded CPython is ready to experiment with by paulddraper on Saturday July 13, 2024 @04:07PM (#40956512)
> should not be written

IDK what l should and shouldn't be written in, but there are a very large # of proud "pure Python" libraries on GitHub and HN.

The ecosystem seems to even prefer them.

Re:Free-threaded CPython is ready to experiment with by fastasucan on Tuesday July 16, 2024 @05:01AM (#40974739)
I never understand this sentiment, that shows up in every topic on python. Who descides why something should or should not be written I Python?

Why shouldn't someone who prefers writing in python benefit from using multiple cores?

Re:Free-threaded CPython is ready to experiment with by phkahler on Tuesday July 16, 2024 @11:43AM (#40977587)
>> Who descides why something should or should not be written I Python? Why shouldn't someone who prefers writing in python benefit from using multiple cores?

I did use the words "most things". I'm not saying this is a bad development for Python, or that nobody should use it. But if performance is a top priority, Python is the wrong language and always has been.

I use Python from time to time, it's fun and easy to put certain kinds of things together quickly. But each time I do a project with it, the first thing I ask myself is "is this going to be fast enough?" If not I'll use something else.