News for hackers. Stuff that matters.
Re:Our Plan for Python 3.13 by dekhn on Thursday June 15, 2023 @10:34AM (#36341121)
The GIL will never be removed from the main python implementation. Histortically, the main value of GIL removal proposals and implementations has been to spur the core team to speed up single core codes.

I think it's too late to consider removing the gil from the main implementation. Like guido said in the PEP thread, the python core team burned the community for 10 years with the 2-3 switch, and a GIL change would be likely as impactful; we'd have 10 years of people complaining their stuff didn't work. Frankly I wish Guido would just come out and tell Sam "no, we can't put this in cpython. You did a great work but compatibility issues trump performance".

Kind of a shame because Hugunin implemented a Python on top of the CLR some 20 years ago and showed some extremely impressive performance results. Like jython, and pypy and other implementations, it never caught on because compatibility with cpython is one of the most important criteria for people dealing with lots of python code.

Re:Our Plan for Python 3.13 by giantrobot on Thursday June 15, 2023 @10:58AM (#36341439)
> Like jython, and pypy and other implementations, it never caught on because compatibility with cpython is one of the most important criteria for people dealing with lots of python code.

I think this is more an issue of popular packages were developed and tested against cpython and there wasn't enough effort available to port/test them against anything else. There's no special magic in cpython that Python programmers love, they just want their code to run. If they've got a numpy dependency (IIRC it doesn't support pypy but I'm not going to look it up so I may be corrected on that point this is a long parenthetical) they can't use an interpreter that doesn't support it. Even if it worked but had bugs it didn't have in cpython, they're still going to use cpython. Most people aren't writing Python for its super duper fast performance so they're fine leaving a little performance on the table by using the interpreter that their dependencies support. Whatever that is.

Re:Our Plan for Python 3.13 by dehrmann on Thursday June 15, 2023 @11:54AM (#36342336)
Jython doesn't have a good story for running native libraries like Numpy.
Re:Our Plan for Python 3.13 by giantrobot on Thursday June 15, 2023 @12:09PM (#36342617)
Sure, I didn't claim it did. My point is that Python programmers don't tend to have a particular fondness for an interpreter. They tend to care only about the ecosystem. If you came up with a cxpython interpreter that was faster than cpython and supported all the modules the same way (including C interop) Python programmers would jump over to it. If your cxpython was faster than cpython but didn't support everything they'd ignore it.

Case in point: Python 2.7. While 3.x offered a lot of improvements it took years for some popular modules to support it. No one bothered to look twice at Python 3 until their dependencies supported it.

Python programmers don't tend to care much about the interpreter so much as the code they wrote or use running correctly.

Re:Our Plan for Python 3.13 by fulafel on Friday June 16, 2023 @08:34AM (#36355525)
Numpy also wasn't very prominent in those days among Python users, the explosion of data science Python use happened later.

(Actually NumPy didn't even exist for most of Jython's active development, but some of its predecessors did)

Re:Our Plan for Python 3.13 by coldtea on Thursday June 15, 2023 @11:15AM (#36341703)
>the python core team burned the community for 10 years with the 2-3 switch, and a GIL change would be likely as impactfu

A core team led by him, which also had the opportunity to make much more impactful changes during 3, including removing the GIL, since they were going to mess up compatibility anyway, but didn't.

All that mess (and resulting split and multi-year slowdown in Py3 adoption) just to put in the utf-8 change and some trivial changes. It's only after 3.5 or so that 3 became interesting.

Re:Our Plan for Python 3.13 by regularfry on Thursday June 15, 2023 @11:23AM (#36341842)
I think that's called "learning from one's mistakes". I hope.
Re:Our Plan for Python 3.13 by paulddraper on Thursday June 15, 2023 @11:20AM (#36341795)
It's hard to argue that Python 3 should have been even less compatible.
Re:Our Plan for Python 3.13 by coldtea on Thursday June 15, 2023 @11:31AM (#36341962)
Is it? It took the 5 year (at least) adoption hit anyway. How worse would it be if it had more features people want?

I'd say it should have been less compatible when needed to add more substantial changes people wanted, as opposed to taking the hit for nothing!

And it should be more compatible for things that were stupid decisions that had to eventually take back, like not having a bytes str solution.

Re:Our Plan for Python 3.13 by paulddraper on Thursday June 15, 2023 @02:18PM (#36344514)
> How worse would it be

8 years

or never

Re:Our Plan for Python 3.13 by misnome on Thursday June 15, 2023 @02:37PM (#36344764)
> How worse would it be

raku

Re:Our Plan for Python 3.13 by coldtea on Thursday June 15, 2023 @02:53PM (#36344971)
Raku failed to timely deliver a stable release. And didn't stick to sensible new features, but tried to make an uber-language with everything plus the kitchen sink, and even a multi-language vm.
Re:Our Plan for Python 3.13 by misnome on Thursday June 15, 2023 @03:42PM (#36345465)
You are literally asking what could happen if Python 3 had done the same.
Re:Our Plan for Python 3.13 by eesmith on Thursday June 15, 2023 @04:49PM (#36346343)
> if it had more features people want

What people wanted was features to help with the migration.

Yes, that of course having those features would have helped.

But doing that required experience the Python developers didn't have when they were doing 3.0!

The Python developers thought people could do a one-off syntactic code translation (2to3), perhaps even at install time, rather than what most people did - write to the common subset of 2 and 3, with helpers like the 'six' package.

What are the "more substantial changes" you propose? The walrus operator? Matching? Other things that Python 3 eventually gained, and which took years in some cases to develop?

Or are you proposing something that would have it more difficult to write to the common subset?

That subset compatibility necessity extends to the Python/C API. Get rid of global state and you'll need to replace things like:

   PyErr_SetString(PyExc_ValueError, "embedded null character");
with something that passes in the current execution state. Make that too hard, and you inhibit migration of existing extension modules, which further inhibits the migration.
Re:Our Plan for Python 3.13 by coldtea on Friday June 16, 2023 @06:24AM (#36354239)
>The Python developers thought people could do a one-off syntactic code translation (2to3), perhaps even at install time

Perhaps they overstimated how much of the change 2to3 would handle, but they surely didn't think that, because they already knew that they put in all kinds of not automatable via "syntactic code translation" changes - where context is needed (e.g. the str changes).

>What are the "more substantial changes" you propose? The walrus operator? Matching? Other things that Python 3 eventually gained, and which took years in some cases to develop?

No GIL, more optimization - a wasted opportunity for a big speed bump, dropping legacy stuff, typing support, an improved C extension model, JIT, specialization, green threads, and so on. Things like the walrus operator would be at the very bottom...

They could have gone for "compatibility" to ease the migration (or make it a non-issue, just run backwards compatibly) sure.

But since they decided to go ahead and break things, and bump the version name, a change the community has been discussing since the mid-90s as some grand vision of big changes, they could have done more substantial stuff at least.

At it stands, they broke compatibility and cost the community 5-6 years for nothing much. Everything big came later in 3.x. And not because it couldn't just as well be added piecemeal to some 2.8 and onwards...

Re:Our Plan for Python 3.13 by eesmith on Friday June 16, 2023 @07:55AM (#36355025)
> but they surely didn't think that

They surely did! And it tells me you don't know the history that well.

You can read PEP 3000 where they say almost exactly that, at https://peps.python.org/pep-3000/ :

  The recommended development model for a project that needs to 
  support Python 2.6 and 3.0 simultaneously is as follows:

  0.  You should have excellent unit tests with close to full coverage.
  1.  Port your project to Python 2.6.
  2.  Turn on the Py3k warnings mode.
  3.  Test and edit until no warnings remain.
  4.  Use the 2to3 tool to convert this source code to 3.0 syntax.
        Do not manually edit the output!
  5.  Test the converted source code under 3.0.
  6.  If problems are found, make corrections to the 2.6 version of
        the source code and go back to step 3.
  When it’s time to release, release separate 2.6 and 3.0 tarballs (or
  whatever archive form you use for releases).
They really did not consider having a usable subset that could work on Python 2 and Python 3. The same PEP says:

  There is no requirement that Python 2.6 code will run unmodified on
  Python 3.0. Not even a subset. (Of course there will be a tiny subset,
  but it will be missing major functionality.)
Remember, it wasn't even until Python 3.3 that they restored the u'unicode' syntax "provided solely to reduce the number of purely mechanical changes in migrating to Python 3, making it easier for developers to focus on the more significant semantic changes (such as the stricter default separation of binary and text data)." https://docs.python.org/3.3/whatsnew/3.3.html

And it wasn't until Python 3.5 that they supported old-style %-formatting, like (b"%d" % n), both because it's useful in wire protocols, and "to help ease migration from, and/or have a single code base with, Python 2" https://peps.python.org/pep-0461/ .

> No GIL ... and so on

The features you listed required years of development, and some, like the JIT support, are still in-progress, while the no-gil proposal seems beyond what the steering committee is willing to accept.

It sounds like you want them to have delivered Python 3.12, with all these features (many of them iterated on over several releases), instead of 3.0, and without any migration path from 2.x Python or Python/C extensions beyond wholesale rewriting.

There is no way they would have manged to timely deliver a stable release following your suggestion. As it was, it took about a decade to deliver a version that had a effective migration pathway. Python 3.5 is the first version I supported, in no small part because it supported bytes % interpolation.

> And not because it couldn't just as well be added piecemeal to some 2.8 and onwards...

Perhaps it could have been done in an abstract and technical sense. But the Python core developers decided they didn't have the resources (money, people, etc) for that path.

I don't see how some of the changes, like exception chaining, could have been implemented without breaking backwards compatibility. Even things as simple as evaluating (a<b) or "Hello".encode("base64") changed at a pretty deep level.

Remember, Python 3 was always meant as "a relatively mild improvement on Python 2, [because] we can gain a lot by not attempting to reimplement the language from scratch." https://peps.python.org/pep-0461/ That was how the effort was justified.

The Perl6/Raku experience was definitely part of the zeitgeist in the discussion against larger changes like you think were needed.

What are your counter-examples that might sooth the concerns should a cusp like this appear in the future? I can't think of any good ones.

> and cost the community 5-6 years for nothing much. Everything big came later in 3.x.

The core developers argued that the technical debt in the code base was high, and while it would take years, those changes would enable the later big improvements you now see.

You seem to look at the big improvements and somehow believe they could have been done 15 years ago, on the old code base, with the available knowledge and resources of the people then.

You believe this because, why?

Re:Our Plan for Python 3.13 by mardifoufs on Thursday June 15, 2023 @11:59AM (#36342421)
Agreed. It would have pushed the 2->3 migration from "very painful for the ecosystem" to a full on perl5->6 break between the two versions. Not sure it would have survived that.
Re:Our Plan for Python 3.13 by __d on Thursday June 15, 2023 @08:27PM (#36349150)
It's not like Python adoption and use was significantly boosted by Python3: it was and would have been just fine without it.

The problem with languages written by language designers/implementers is that they often don't know when to stop. Wirth is a shining example here: Pascal -> Modula(n) -> Oberon. You need to move on, and leave the old alone.

Re:Our Plan for Python 3.13 by progmetaldev on Thursday June 15, 2023 @08:51PM (#36349372)
I believe it's a lot easier to state this long after the migration took place. Removing the GIL, or any host of other changes, could have split the community to a place where the language would have been abandoned except amongst a small minority.

At this point, removing the GIL is such a large change, it would probably be better to wait for the end of (practical) performance to single-threaded code, and then remove the GIL. At that point you would have a community consensus behind the change, and the holdouts wouldn't have a stranglehold on keeping the community from moving forward.

I'm not sure if I would call the move from 2 -> 3 a trivial change, but maybe you're more well versed in Python than I am (and I'm fully willing to admit that may be the case).

Re:Our Plan for Python 3.13 by Izkata on Friday June 16, 2023 @10:37AM (#36357235)
It was such a big screwup they had to backtrack on one of the changes, resulting in 2.7 -> 3.3 being easier than 2.7 -> 3.0
Re:Our Plan for Python 3.13 by bornfreddy on Friday June 16, 2023 @01:31PM (#36360551)
Do you have in mind u'unicode' syntax?
Re:Our Plan for Python 3.13 by Izkata on Friday June 16, 2023 @01:40PM (#36360703)
Yep
Re:Our Plan for Python 3.13 by jedberg on Thursday June 15, 2023 @11:32AM (#36341979)
> The GIL will never be removed from the main python implementation.

I don't see why. It's a much easier transition than 2 to 3.

Make each package declare right at the top if they are non-GIL compatible. Have both modes available in the interpreter. If every piece of code imported has the declaration on top, then it runs in non-GIL mode, otherwise it runs in classic GIL mode.

At first most code would still run in GIL mode, but over time most packages would be converted, especially if people stopped using packages that weren't compatible.

Re:Our Plan for Python 3.13 by dekhn on Thursday June 15, 2023 @11:44AM (#36342145)
I'm sorry but I really don't think it's "easy" and your suggestion would be just part of a much, much larger solution.
Re:Our Plan for Python 3.13 by powersnail on Thursday June 15, 2023 @11:41AM (#36342106)
Python would be too dynamic a language to have non-GIL compatibility declared simply at top. Code can be imported/evaled/generated at runtime, and at any part of a script, which means that python would need to be able to switch from non-GIL to GIL at any time of execution.
Re:Our Plan for Python 3.13 by jedberg on Thursday June 15, 2023 @12:02PM (#36342473)
It's true that there are dynamic imports, but presumably it would be on the library maintainer to know about that, but also you could throw a catchable error about GIL imports or something like that.

All I'm saying is that it's solvable, and more solvable than 2 to 3.

Re:Our Plan for Python 3.13 by samwillis on Thursday June 15, 2023 @12:26PM (#36342909)
I completely agree, something like:

   from __future__ import multicore
(The proposal seems to be to call it that rather than "no Gil" as it's more positive)

And maybe if done in an __init__.py it applies to the whole module.

Do that for v3.x then drop it completely for v4

I think the issue may be that maintaining both systems is too complex.

Re:Our Plan for Python 3.13 by richdougherty on Thursday June 15, 2023 @02:53PM (#36344970)
I mean that seems horribly tricky, but also totally doable.

Having read about JavaScript/Java VM optimisations in JITs and GC I would be surprised if a global state change like this is not manageable - think deoptimising the JS when you enter the debugger in the dev tools in your browser.

Re:Our Plan for Python 3.13 by blibble on Thursday June 15, 2023 @03:25PM (#36345285)
Java-the-bytecode is as dynamic yet somehow hotspot manages to be rather nippy
Re:Our Plan for Python 3.13 by throwaway2037 on Friday June 16, 2023 @06:36AM (#36354331)
This is wildly misunderstood by many just how insanely good is the current JVM. It scares me how much it has improved in the last ten years. Since it has been open source for a long time, many university researchers have done experiments and proposed HotSpot improvements. Plus, Sun/Oracle employs a small army of PhD researchers to work on it "night and day". If Project Valhalla ever sets sail (pun intended), I could imagine other languages begin to target JVM instead of their own (worse) VM. (Raku talked about it a few years ago.) When I need to move from Java to Python, I am always painfully reminded how terrible is the VM performance in a tight loop that does not use list comprehension.
Re:Our Plan for Python 3.13 by superq on Saturday June 17, 2023 @06:35PM (#36375407)
I'm no fan of Python after the 2-3 debacle, but to be fair, you're comparing apples and oranges here. Why not instead compare it to another C-like language (Java was originally intended to be the replacement for C++ back in 1995, and Python dates back to 1989.)

Go or Rust, or even Erlang or Haskell would be great examples that are more inline with the design goals (then and now) of Java.

Re:Our Plan for Python 3.13 by throwaway2037 on Monday June 19, 2023 @08:47PM (#36398344)

    comparing apples and oranges
That is exactly my point. People start a small project in Python. Velocity is very high. Then, the project grows into a monstrosity. Suddenly, the awful Python "VM" (slow as hello) and lack of true multi-threading are major project liabilities. They should have started with someone much less sexy: DotNet (C#) or Java. Repetitive? Hell yes, but easy to maintain and cheap to hire devs.
Re:Our Plan for Python 3.13 by lizmat on Monday June 19, 2023 @07:59AM (#36390031)
FWIW, the JVM is one of the supported backends of the Raku Programming Language. Has been for quite some time actually. It was the first additional backend supported after Parrot, and provided a template for supporting the MoarVM and Javascript backends since then.
Re:Our Plan for Python 3.13 by phire on Thursday June 15, 2023 @06:22PM (#36347479)
That's not an insurmountable problem.

As long as all the data structures stay the same, all you really need to do is flush out all the non-GIL bytecode and load in (or generate) GIL bytecode.

Sure, there might be a stutter when this happens. You will also want a way to either start in GIL mode, or force it to stay in non-GIL mode, throwing errors. But it's a very solvable problem.

Re:Our Plan for Python 3.13 by Karellen on Thursday June 15, 2023 @07:45PM (#36348674)
> all you really need to do is [SMOP]. But it's a very solvable problem.

Awesome! I look forward to seeing your PR shortly. ;-)

Re:Our Plan for Python 3.13 by throwaway2037 on Friday June 16, 2023 @06:29AM (#36354274)
I too enjoyed the parent comment. It's right up there with "as soon as we have sufficiently smart enough compilers, that won't be an issue anymore".

I needed to Google SMOP, which tells me: "small matter of programming". Correct?

Re:Our Plan for Python 3.13 by phire on Friday June 16, 2023 @08:20AM (#36355381)
I'm confused. Why do people think my suggested solution is difficult enough to be comparable to the halting problem or "a smart enough compiler"?

We are talking about a scenario where cpython has already been modified to support both GIL and non-GIL operating modes, and a set of libraries that support the new non-GIL mode have been manually annotated by programmers.

All I'm suggesting is that on top of this, we modify the "load library" code to detect at runtime when we are loading a library that doesn't support the new non-GIL mode and switch modes.

Re:Our Plan for Python 3.13 by throwaway2037 on Friday June 16, 2023 @10:43PM (#36366708)
This simplest solution is to get a patch accepted by Python team. Good luck with that.
Re:Our Plan for Python 3.13 by Karellen on Friday June 16, 2023 @11:15AM (#36358008)
> I needed to Google SMOP, which tells me: "small matter of programming". Correct?

Yes, it can mean either "small..." or "simple matter of programming", which is more the meaning I had in mind. But either fit.

Re:Our Plan for Python 3.13 by gnulinux on Thursday June 15, 2023 @09:22PM (#36349655)
There is no programming language problem related to concurrency and C-level APIs that change the amount of code Python represents that is NOT insurmountable. This is like linux "we don't break userspace" motto. There is conceivably no possibility of removing GIL without breaking the userspace. Programs will be buggy, some will stop working. Worse, until someone works around the halting problem, we can't just crawl python code and decide if it uses GIL. People will have to be paid to inspect one function at a time to determine where GIL is needed.
Re:Our Plan for Python 3.13 by phire on Friday June 16, 2023 @12:34AM (#36351304)
Removing the GIL is easy. It's already been done with Jython and IronPython. No changes to python code is needed.

You do still need locks for concurrency, it's just that instead of a corse-grained global lock, you replace it with a bunch of fine-grained locks. Which is actually one of the sticking points with the proposal to remove the GIL. All those fine-grained locks actually impact performance for a single-threadded python programs.

The impossible problem is removing the GIL without breaking compatibility with the cpython API; There is a bunch of non-python code (mostly c/c++) that interfaces to python code with the cpython API and it's that code which breaks when you remove the GIL.

The proposals floating around don't actually fix that issue, it's more of a "let's break API compatibility anyway", allowing libraries to be updated the new API incrementally.

There are no issues with the halting problem here. It's really easy to detect at runtime if python code is interacting with c/c++ code via the old cpython API. Remember, the halting problem only applies to static analysis, not dynamic runtime checks.

Re:Our Plan for Python 3.13 by gnulinux on Friday June 16, 2023 @01:34PM (#36360602)
This is extremely naive, and you answer your own question:

> [Par 2] ["Removing GIL creates performance costs that people don't want"]

> [Par 3] ["Removing GIL breaks CPython API which tons of codebases rely on and people will have to be paid to fix all that code"]

In short, it's not possible to remove GIL without requiring code change.

> There are no issues with the halting problem here. It's really easy to detect at runtime if python code is interacting with c/c++ code via the old cpython API. Remember, the halting problem only applies to static analysis, not dynamic runtime checks.

This is not true and you're thinking of this wrong. When presented with a "will my code work after GIL removal" type of problem, the question becomes "will my code run C/C++ API". Whether it's detected at runtime is irrelevant because the question you want to answer is "does this piece of software require any change at all to work without GIL". To do that, you need a tool that statically analyzes whether known-bad functions (those that run C/C++ functions trivially/deterministically) are called from the rest of the codebase.

Imagine you work for a company that has a package "xyz" written in C/C++ called in Python. Now that GIL is removed in an imaginary Python 4, my boss comes to me and asks "how much code needs to be changed for us to port to Python 4". Now, you can apply heuristics such as "how many modules import xyz". But since the correctness implications are co-infective, any module that doesn't import xyz but imports a module that import xyz will be affected as well. You can be more granular and verify whether individual functions use objects in xyz. Which brings me to my original point that there are two cases, either this is a static analysis problem (which we lack) or it's work someone has to crawl the entire codebase, inspect function by function, run unittest by unittest to determine if GIL removal breaks anything. I know because people did exactly this in 2 -> 3 change and it's an extraordinarily expensive ($$$) transition. Your view is naive beyond comprehension and it's hard to think of GIL removal as anything easier than the 2 -> 3 transition which was a shitshow of the magnitude software industry hasn't seen before.

Re:Our Plan for Python 3.13 by phire on Friday June 16, 2023 @02:28PM (#36361445)
It's super easy to check if any C/C++ code has been imported. Not too hard to get a reasonably good result with static analysis, just find all import statements and see if it maps to a python file or a dll/so file, recusing as needed. You don't need to look at any other code except the import statements.

For an even better result the main python interpreter can be modified with a flag to just list all imported dll/so files. Run your application with that flag and see what it imported and it will catch weird edge cases (like, python code that messes with import paths)

There is no need to check the entire codebase. It's only the C/C++ code that directly uses the cpython api that needs to be checked. Any python code can be ignored, along with C/C++ code that doesn't interact with the cpython API.

This isn't like the 2 -> 3 transition where you needed to touch almost every line of python code. The amount of touched code for most companies should be tiny.

Also, the proposal isn't for a python 4 were everyone is required to upgrade to this new paradigm. It's for an optional mode that allows running without the GIL. The only people who actually need to worry about it are people who want multithreadding.

Your theoretical company can do a quick check to see what c/c++ libraries are imported and estimate how much code would need to be checked. If it's too daunting, they can just keep operating with the GIL enabled.

Re:Our Plan for Python 3.13 by gnulinux on Tuesday June 20, 2023 @11:57AM (#36405967)
> Your theoretical company can do a quick check to see what c/c++ libraries are imported and estimate how much code would need to be checked. If it's too daunting, they can just keep operating with the GIL enabled.

Once again, this doesn't make sense and you're simply naively glossing over things. This won't work because likely one of your dependencies use no-GIL mode (such as numpy or something like that). This essentially forks the ecosystem into two, and if you have a 5 million LoC GIL python code you have no way of importing a no-GIL dependency. Nobody will sign up for that kind of mess, python package management is already a huge mess. What happens if the library goes from GIL to no-GIL? Runtime exception. Yeah, thanks but no thanks.

Beyond that, it's unclear how best to respond to your comment about static analysis being easy and that you don't need to inspect python code line by line. It needs to be understood that there are companies who have millions of lines of code where code is mixed with C/C++ FFI calls all over the place. I have a codebase like that where almost everything is FFI/Python mixed. I know many companies do. In our case we do need to go line by line to see what's inspected. Even if we don't, our boss will ask us to because if anything fails it'll be our responsibility so we at least need to do the busy work of confirming nothing is affected. It seems like you suffer from the problem that you identify a small subset of reality, then determine the solution you propose is practical, when in real life it causes tons of codebases to be almost rebuilt. Knowing Python folks, I know no one has any interest in such a thing.

Re:Our Plan for Python 3.13 by aprdm on Thursday June 15, 2023 @12:12PM (#36342664)
This is very naive.
Re:Our Plan for Python 3.13 by xapata on Thursday June 15, 2023 @02:17PM (#36344505)
jedberg doesn't seem like a naïve person, glancing at his work history. Perhaps you could explain why you think this opinion is naïve?
Re:Our Plan for Python 3.13 by Eisenstein on Thursday June 15, 2023 @02:35PM (#36344744)
"There are two types of programmers: new ones who don't know how complicated things are, and experienced ones who have forgotten it" -from an article on HN the other day about setting up python envs.
Re:Our Plan for Python 3.13 by execveat on Thursday June 15, 2023 @03:44PM (#36345486)
There also are programmers who are aware of much more complicated things being done in sister projects, like JVM and JS runtimes in this case.
Re:Our Plan for Python 3.13 by xapata on Thursday June 15, 2023 @05:31PM (#36346785)
An appeal to authority? I suppose it'd be better if you named the article's author or linked to it.
Re:Our Plan for Python 3.13 by Eisenstein on Thursday June 15, 2023 @05:46PM (#36347010)
Not appealing to anyone; I thought it was a clever quote.

* https://www.bitecode.dev/p/why-not-tell-people-to-simply-use

EDIT -- Here is the quote:

There are usually two kinds of coders giving advises. A fresh one that has no idea how complex things really are, yet. Or an experienced one, that forgot it.

Re:Our Plan for Python 3.13 by xapata on Friday June 16, 2023 @04:41PM (#36363547)
It's clever, but like (almost) all such things, doesn't always apply.
Re:Our Plan for Python 3.13 by dekhn on Thursday June 15, 2023 @05:46PM (#36347007)
Even skilled programmers often make the mistake of saying "why don't you just..." or "it's easy, just..." when completely ignoring large important factors, such as following process, ensuring backward compatibility, stakeholder alignment (ugh), and addressing long tail problems.
Re:Our Plan for Python 3.13 by xapata on Friday June 16, 2023 @04:43PM (#36363563)
Yes, but it's reasonable to note such things instead of simply derogating the remark.
Re:Our Plan for Python 3.13 by Groxx on Thursday June 15, 2023 @03:37PM (#36345410)
I don't see why you wouldn't have holdouts using GIL for valid single-threaded performance reasons for years/decades. And that's ignoring legacy code - even 2.7 is still alive and kicking in some corners.
Re:Our Plan for Python 3.13 by jedberg on Thursday June 15, 2023 @03:42PM (#36345466)
I'm sure you would, but anyone who cared about it would work around it, either by not using that library or finding a different one or even forking the one that isn't updated. Just like most people use Python 3.x now, but there are some 2.7 holdouts. But those holdouts aren't holding back the entire ecosystem at this point.
Re:Our Plan for Python 3.13 by Groxx on Thursday June 15, 2023 @10:30PM (#36350301)
They did for many, many years. And the result soured many devs and companies on Python. And many libraries have not been migrated.

But yes, I'm very glad they've been cut off now. It does eventually shift to just the new stuff.

Re:Our Plan for Python 3.13 by zarzavat on Thursday June 15, 2023 @11:34PM (#36350814)
The difference is that no-GIL is a minority use case. Most people are using Python in single threaded workflows (numpy/scipy, machine learning, build scripts, etc etc) and who don’t care about the GIL. The GIL mostly affects webdevs.

Probably the library support will be much worse than 2-3, but if only a minority of users are impacted by libraries that don’t support it then it’s not a big issue. GIL concerned users can either carefully select their dependencies to be no-GIL supporting, or they can decide to go with the GIL.

2-3 was bad because every single library, app, and tiny script had to be migrated, if it used a string or a print statement.

Re:Our Plan for Python 3.13 by Dork1234 on Thursday June 15, 2023 @11:50AM (#36342240)
I really think the GIL is saving a bunch of poorly written multi-threaded C++ wrappers/libraries out there. If they remove it, a bunch of bugs will appear in other libraries that might not be Pythons fault.
Re:Our Plan for Python 3.13 by eklitzke on Thursday June 15, 2023 @12:53PM (#36343346)
They're not "poorly written", the fact that you don't need to do any locking in C/C++ code is part of the existing Python API. Right now when Python code calls into C/C++ code the entire call is treated as if it's a single atomic bytecode instruction. Adding extra locking would just make the code slower and would accomplish absolutely nothing, which is why people don't do it.
Re:Our Plan for Python 3.13 by tinus_hn on Thursday June 15, 2023 @02:41PM (#36344824)
The interpreter could do locks around these calls automatically to make them atomic, while leaving itself multithreaded.
Re:Our Plan for Python 3.13 by KMag on Thursday June 15, 2023 @05:12PM (#36346567)
In order for the call into C to appear atomic to a multithreaded interpreter, all threads in the interpreter would need to be blocked during the call. That's possible to do, but you've just re-introduced the GIL whenever any thread is within a C extension.

In the unlocked case, one could use low-overhead tricks used for GC safepoints in some interpreters. One low-overhead technique is a dedicated memory page from which a single byte is read at the beginning at of every opcode dispatch, and you mark that page non-readable when you need to freeze all the threads executing in the interpreter. You'd then have the SIGSEG handler block the threads until the one thread returned from C. That's fairly heavy in the case it's used, but pretty light-weight if not used.

Re:Our Plan for Python 3.13 by enedil on Thursday June 15, 2023 @01:02PM (#36343510)
Nevertheless, this is still a concern to wider ecosystem, if Python libraries suddenly start to break due to underlying issues. I don't think this can be neglected.
Re:Our Plan for Python 3.13 by silverwind on Thursday June 15, 2023 @03:21PM (#36345237)
Like in any other language, it's best to avoid non-native dependencies.
Re:Our Plan for Python 3.13 by _aavaa_ on Friday June 16, 2023 @10:33AM (#36357175)
Unfortunately, that's simply impossible if you want to approach >10% of your machines power when using python.
Re:Our Plan for Python 3.13 by zackees on Thursday June 15, 2023 @12:42PM (#36343176)
I agree with this take.

The GIL is hiding all kinds of concurrency bugs. If the CPython team default disable it then all hell is going to break loose.

It's better to carve out special concurrency constructs for those that need it.

Re:Our Plan for Python 3.13 by nomel on Thursday June 15, 2023 @12:55PM (#36343387)
Not sure why this was flagged dead. If you look at many stackoverflow answers, around threading, many explicitly rely on the GIL, quoting source/documentation “proving” that it’s safe, avoiding the use of threading.Lock() and the like.

As an early python programmer, I copy pasted these types of answers. My old threaded code absolutely has these bugs. I’ve even seen code in production that has these bugs, because they’re sometimes dumb performance enhancements, rather than bugs, unless you happen to use a Python interpreter without a GIL, especially one that that doesn’t exist yet.

Great care would have to be taken to make sure the GIL was not disabled by default, for anything an existing thread touches (or some super, dynamic aware, smarts to know if it can be disabled).

Re:Our Plan for Python 3.13 by tomn on Thursday June 15, 2023 @04:22PM (#36345970)
I believe that GIL-removal projects aim to preserve this behaviour:

https://peps.python.org/pep-0703/#container-thread-safety

That's why gilectomy carries an unreasonable single-threaded performance cost: many operations now need to take a lock where before they relied on the GIL.

Re:Our Plan for Python 3.13 by umanwizard on Thursday June 15, 2023 @05:46PM (#36347006)
Why do you consider code that relies on the GIL to be buggy? Isn't the GIL a documented, stable part of Python? (Hence why it will probably never be removed).
Re:Our Plan for Python 3.13 by nomel on Friday June 16, 2023 @01:20PM (#36360342)
5th sentence in my comment:

> I’ve even seen code in production that has these bugs, because they’re sometimes dumb performance enhancements, rather than bugs, unless you happen to use a Python interpreter without a GIL, especially one that that doesn’t exist yet.

Re:Our Plan for Python 3.13 by miraculixx on Thursday June 15, 2023 @06:46PM (#36347808)
The GIL protects interpreter resources, not your program. If you have concurrent access to your own objects you need your own locks.
Re:Our Plan for Python 3.13 by nomel on Monday June 19, 2023 @02:00AM (#36387771)
“Interpreter resources” are just python primitives, from the user perspective. And, from that perspective, you can sometimes get away without using user managed locks, by relying on the GIL, in your objects. For example, you can trivially use a list as a multi threaded queue, using `.append()` and `.pop()`.
Re:Our Plan for Python 3.13 by lacker on Thursday June 15, 2023 @12:54PM (#36343362)
I think it's too late to consider removing the gil from the main implementation.

I think it'll happen one day. Is Python going anywhere?

Give it 20 years. The 2 -> 3 switch will be like the Y2K bug, only remembered by the oldest programmers. The memories of pain will fade, leaving only entertaining war stories. The GIL will still be there, and still be annoying.

Then, when everyone has forgotten, the community will be ready. For an incredibly long and grinding transition to Python 4.

Re:Our Plan for Python 3.13 by ActorNightly on Thursday June 15, 2023 @02:12PM (#36344433)
In 20 years, you wouldn't have Python 4. You will have something like ChatGPT that you interact with and it writes code for you, down to the machine level instructions that are all hyperoptimized. Coding will be half typing, half verbal.
Re:Our Plan for Python 3.13 by jwandborg on Thursday June 15, 2023 @02:36PM (#36344753)
Imagine debugging hyperoptimized machine code. - Or would you just blame yourself for not stating your natural language instructions clearly enough and start over? I guess all of these complex problems would somehow be solved for everyone within the next 21 years and 364 days.
Re:Our Plan for Python 3.13 by ActorNightly on Thursday June 15, 2023 @02:46PM (#36344888)
You wouldn't debug it directly. The interaction will be something like telling the compiler to run the program for a certain input, and seeing wrong output, and then saying, "Hey, it should produce this output instead".

The algorithm will be smart enough to simply regenerate the code minimally to produce the correct output.

Re:Our Plan for Python 3.13 by ilc on Thursday June 15, 2023 @03:30PM (#36345335)
I think you have described a new definition of hell.
Re:Our Plan for Python 3.13 by dumpsterdiver on Thursday June 15, 2023 @05:54PM (#36347143)
Yeah, when people start running into weird failure modes with no insight into the code... sounds like a nightmare.
Re:Our Plan for Python 3.13 by ActorNightly on Friday June 16, 2023 @06:45PM (#36364997)
Input output mapping. Point out what output should be for any failure mode and compiler will auto fix the code
Re:Our Plan for Python 3.13 by m4rtink on Thursday June 15, 2023 @04:22PM (#36345981)
Good luck with that.
Re:Our Plan for Python 3.13 by jamann on Saturday June 17, 2023 @09:16AM (#36369925)
What you wrote is naive. I dont think AI will ever be able to guess what correct output for arbitrary inputs should look like, just based on examples. You need to specify an algorithm that produces the correct output for all inputs. AI could be able to optimize that, but not fill in gaps in the definition of the goal.
Re:Our Plan for Python 3.13 by timacles on Thursday June 15, 2023 @06:32PM (#36347618)
While titillating to think about, what you're describing is more than 20 years away for AI. The best it could do is that for generalized problems, to actually write new original code and complex code is not within the bounds of current AI capabilities.
Re:Our Plan for Python 3.13 by gnulinux on Thursday June 15, 2023 @09:27PM (#36349704)
Yeah, I bet nothing of that sort happens. This programming sci-fi is entertaining to read but it's not grounded in reality.
Re:Our Plan for Python 3.13 by jay_kyburz on Thursday June 15, 2023 @08:05PM (#36348923)
Wat! I'm experiencing 2-3 pain right now! Google has given me till January next year to port all my apps that have been running happily for 10 years. It's no small job either.

I'm already in a state where I can't upgrade to the latest gcloud tools because 2.7 is removed from them. I'm stuck on a version from late last year until I've finished my ports or abandon my projects.

I was a very happy user of GAE standard for many many years, but they burned me in the end and I've learnt my lesson about building on proprietary tools.

Standard frameworks and standard databases for me from now on!

Re:Our Plan for Python 3.13 by ptx on Monday June 19, 2023 @04:04PM (#36395859)
That's 4 years after the EOL of Python 2.7: https://www.python.org/doc/sunset-python-2/
Re:Our Plan for Python 3.13 by londons_explore on Thursday June 15, 2023 @01:57PM (#36344250)
> compatibility issues trump performance".

Surely it would be possible to drop back to GIL mode if any c extension is loaded which is incompatible with running lockless?

Then you usually get speed, yet still maintain compatibility.

Re:Our Plan for Python 3.13 by mlyle on Thursday June 15, 2023 @03:09PM (#36345115)
> if any c extension is loaded which is incompatible with running lockless?

It'd be slightly magical to do. You'd probably have a giant RWLock, which is used for checking whether you're in the "lock free" mode. But at least almost all code could hit it only for read, and it could go away one day.

Re:Our Plan for Python 3.13 by takeda on Thursday June 15, 2023 @01:58PM (#36344257)
I wouldn't say that GIL will never be removed, but I believe the GIL cannot be removed without breaking a lot of existing code.

That means there could be another drama with migrations if that would be done.

I think the most likely way they can effectively eliminate GIL would be to provide a compile option that would basically say "this enables paralellization, but your code is bo longer allowed to do A, B, C (there probably would be a lot more things)"

People who want to get it would then adapt their code, and there could be pressure for other packages to make them work in that mode.

Re:Our Plan for Python 3.13 by godelski on Thursday June 15, 2023 @09:35PM (#36349781)
> Histortically, the main value of GIL removal proposals and implementations has been to spur the core team to speed up single core codes.

While I'm all for increasing single threaded performance[side rant] is this really a good argument? My understanding is that Moore's Law only currently exists because of the existence of more cores. Clock frequency has stagnated since 2004[0]. I mean feature size (Moore's Law) still exists[1] but IPS/core seems significantly flatter than IPS[2]. Aren't most of our performance gains from mutlicore? And as we push more in this direction (e.g. GPU taking over compute) doesn't this make this even worse for python? (Yes I understand that you can make C/CUDA calls but doesn't the GIL make problems here as well as prevent a native python solution?)

[side rant] Still frustrated by things like that difference in speeds between math.sqrt(2.) (~0.002s/10k), np.sqrt(2.) (~0.010/10k), torch.sqrt(torch.tensor([2.])) (~0.039/10k). I know there's more going on in capabilities, but it is of course frustrating by the large differences.

[0] http://cpudb.stanford.edu/visualize/clock_frequency

[1] http://cpudb.stanford.edu/visualize/technology_scaling

[2] https://en.wikipedia.org/wiki/Instructions_per_second#Millio...

Re:Our Plan for Python 3.13 by aragilar on Thursday June 15, 2023 @10:23PM (#36350234)
That difference (at least in the math->numpy case) is entirely down to conversions (or at least it was when I profiled it ~7 years ago). If you're careful with types (i.e. avoiding converting from float to numpy scalar values), then the difference disappears.