News for hackers. Stuff that matters.
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.