Live data from Hacker News

Intent to approve PEP 703: making the GIL optional

discuss.python.org

491–500 of 513 posts

Re: Intent to approve PEP 703: making the GIL optional

#491

Earlier quoted context omitted.

There will be 5+ years of parallel gil/nogil builds. Every library developer will have to deal with this at some point.

You do realize that this grace period is intended precisely to make it easier for libdevs to adapt, yes? 3rd item in the list in the linked article, quote: "We also need to bring along the rest of the Python community as we gain those insights and make sure the changes we want to make, and the changes we want them to make, are palatable." End quote. Yes, library developers have to keep up with developments in the und…

No, for C/C++ you don't have to do anything unless the compiler writers add yet another new warning to -Wall -W, which you have to disable because it is spurious.

Java is more backwards compatible, so is Common Lisp.

Someone here said that the thread on the Python "discussion" forum was shut down. That does not sound like everyone except for the proponents is supposed to be heard (or is even aware of the discussion).

Re: Intent to approve PEP 703: making the GIL optional

#492

Earlier quoted context omitted.

It's in the "Py_mod_gil Slot" section [0] in the PEP: > In --disable-gil builds, when loading an extension, CPython will check for a new PEP 489-style Py_mod_gil slot. If the slot is set to Py_mod_gil_not_used, then extension loading proceeds as normal. If the slot is not set, the interpreter pauses all threads and enables the GIL before continuing. Additionally, the interpreter will issue a visible warning naming th…

Here's what's puzzling me about this: Why then is there even a need for a seperate nogil build? If it is like this says, wouldn't it be easier to just make the standard build switch to gil or nogil automatically (or honor the users choice). The fact that the SC thinks having two versions suggests there is more complexity involved than this section of the PEP leads readers to believe.

Because it's being prudent. With such a big project, the unknown unknowns are numerous.

Something nobody though about lurks in this nogil build, and we are only going to find out when it goes to prod and users report about it.

Instead of breaking the entire Python community's code, the risk is opt-in for a few years.

Re: Intent to approve PEP 703: making the GIL optional

#493

Earlier quoted context omitted.

GIL blocks parallelism for ThreadPool. But I have the same question as you have if we add another coming concurrency model: SubinterpreterThreadPool, which will be possible with the per-interpreter GIL in python 3.12 and later. That's another new model that is already confirmed to be coming: interpreters (isolated from each other) in the same process, that can run with each their own GIL.

Are we talking about "PEP 554 – Multiple Interpreters in the Stdlib"[1] proposal? [1] https://peps.python.org/pep-0554/

Yes and https://peps.python.org/pep-0684/ which is no longer a proposal, but it's also been implemented in CPython 3.12.

with PoC of the parallelization code being developed here https://github.com/jsbueno/extrainterpreters

Re: Intent to approve PEP 703: making the GIL optional

#494

Earlier quoted context omitted.

Yes, used for decades - and for good reason and benefit. No, no the same thing. Sharing objects between processes is not easily achieved for various reasons (at least in Python). It would be easier to get it in multithreading with an arena based allocation model where objects live in a shared or non-shared area of memory. Also it's not my idea. I am just advocating it as the better model for Python to advance to. It…

> It would be easier to get it in multithreading with an arena based allocation model where objects live in a shared or non-shared area of memory. That still relies on IPC, and the associated kernel overhead to set, ctl and access the shared memory, IN ADDITION to the kernel overhead of having to do a context switch between processes. Threads only rely on the context switch. > I am just advocating it as the better mo…

> That still relies on IPC, and the associated kernel overhead to set, ctl and access the shared memory, IN ADDITION to the kernel overhead of having to do a context switch between processes.

In multithreading there is no need for a context switch. Also memory is automatically shared by all threads. The arena model can be completely managed by Python.

I don't get why the SC has not chosen this. Well, I do get it, but it don't like what it implies.

Re: Intent to approve PEP 703: making the GIL optional

#495
The creator and lead maintainer of SQLAlchemy, one of the most popular and most used Python libraries for accessing databases (who doesn't?) gave a rather interesting response to PEP703.

> Basically for the moment the GIL-less idea would likely be burdensome for us and the fact that it's only an "option" seems to strongly imply major compatibility issues that we would not prefer.

(...)

> Adding an entirely new mode of operation to cPython that's optional would be an enormous burden for us as far as ensuring we use APIs appropriately, adding support, testing, we would have to spin up new test workers to test SQLAlchemy in both modes of operation, we would be getting strange new race condition related issues reported

https://github.com/sqlalchemy/sqlalchemy/discussions/10002#d...

Re: Intent to approve PEP 703: making the GIL optional

#496
post #491

Earlier quoted context omitted.

You do realize that this grace period is intended precisely to make it easier for libdevs to adapt, yes? 3rd item in the list in the linked article, quote: "We also need to bring along the rest of the Python community as we gain those insights and make sure the changes we want to make, and the changes we want them to make, are palatable." End quote. Yes, library developers have to keep up with developments in the und…

No, for C/C++ you don't have to do anything unless the compiler writers add yet another new warning to -Wall -W, which you have to disable because it is spurious. Java is more backwards compatible, so is Common Lisp. Someone here said that the thread on the Python "discussion" forum was shut down. That does not sound like everyone except for the proponents is supposed to be heard (or is even aware of the discussion).

> No, for C/C++ you don't have to do anything

Even for such stable languages, a library maintainer has to, at the very least, patch security problems as they are discovered.

> That does not sound like everyone except for the proponents is supposed to be heard (or is even aware of the discussion).

There is an official poll among the Python core devs, linked in the article, which shows overwhelming support for the change. Since they are the ones who have to work this out, that's the only discussion about this that is relevant.

Re: Intent to approve PEP 703: making the GIL optional

#497

Earlier quoted context omitted.

Even pure python code could have race conditions with the GIL disabled. Stuff like accessing and modifying a dictionary item in python code is assumed and currently guaranteed to be atomic because of the GIL. Remove the GIL and decades of assumptions break.

In Python, race conditions with the GIL will be race conditions without the GIL, and vice versa. ....I believe so. E.g. there's no plan to make lists, dicts, thread unsafe.

But it's going to be much easier to demonstrate data consistency issues and bugs due to threading

Re: Intent to approve PEP 703: making the GIL optional

#498

Earlier quoted context omitted.

> context switch between threads is less expensive that switching a new process onto the core But the overhead of a context switch for a thread and process is very similar. The main difference is whether memory is shared by default.

> is very similar. Except that the threads share the exact same virtual address space, and processes do not, which makes the thread context switch faster. And that is to say nothing about the setup and teardown process, which for a process involves copy-on-demand'ing the entire memory, but for a thread merely setting up its own stack.

> Except that the threads share the exact same virtual address space, and processes do not, which makes the thread context switch faster

That's what I said. But it's really not much. I'm afraid we will need numbers now to continue the conversation. If I measured would you be open to changing your opinion? Or are you committed to this topic, so that it would have no bearing?

Re: Intent to approve PEP 703: making the GIL optional

#499
post #46

Why would you even want a no-GIL Python? Java and C showed how much more effort it takes to maintain slower thread safe code for no real benefit. Parallelize at the fork level or at the isolated numeric library level.

What an ignorant comment. No real benefit? Really?

The website you're using likely benefits immensely from thread-safe code. The browser you're using benefits immensely from thread-safe code. Your entire user experience using the modern internet is in an ecosystem of thread-safe code which you apparently are completely oblivious to.

There are a lot of threading models besides Java and C's as well, which you're apparently also unaware of.

Why would you assume you know all the possible use cases of a multi-purpose programming language?

Re: Intent to approve PEP 703: making the GIL optional

#500

Earlier quoted context omitted.

> is very similar. Except that the threads share the exact same virtual address space, and processes do not, which makes the thread context switch faster. And that is to say nothing about the setup and teardown process, which for a process involves copy-on-demand'ing the entire memory, but for a thread merely setting up its own stack.

> Except that the threads share the exact same virtual address space, and processes do not, which makes the thread context switch faster That's what I said. But it's really not much. I'm afraid we will need numbers now to continue the conversation. If I measured would you be open to changing your opinion? Or are you committed to this topic, so that it would have no bearing?

Well, I don't know how you'd test that, but you should really consider testing the other half of the post you're responding to which you ignored, because that's much easier to test:

Spin up and tear down a million pthreads in C, and see how long that takes and how much memory it takes. Then spin up and tear down a million processes in C and see your computer grind to a halt until you kill the process that is starting the processes, if you can even get your computer to do that without power-cycling.

It's Notably, my confidence here comes from the fact that I don't generally get into performance arguments without having actually tested what I'm saying. I've written this code before--it's what I do whenever I'm checking out a new programming language or threading library. Given the complexity of modern computers, nobody really can predict how a program will behave without testing it (except maybe in assembly) there's just too many variables. So you should stop doing that.

If you decide to try the same thing in Java (the other language mentioned), probably drop the number of threads/processes down to 100,000, since Java's lightweight threads aren't quite as efficient. 100,000 processes will probably still be enough to crash your computer.

I'm sure you can find some language/library which implements threads particularly inefficiently, so let's stick to pthreads/C and avoid that straw man.

EDIT: Here ya go, I had ChatGPT write this one for ya:

    #include 
    #include 
    #include 

    void* threadFunction(void* arg) {
      // Sleep for 10 seconds
      sleep(10);
      pthread_exit(NULL);
    }

    int main() {
      int numThreads = 1000000;
      pthread_t threads[numThreads];

      // Create threads
      for (int i = 0; i 
And...

    #include 
    #include 
    #include 
    #include 

    int main() {
      int numProcesses = 1000000;
      pid_t childPID;

      // Create processes
      for (int i = 0; i  0);

      return 0;
    }
It looks like the latter just crashes the program without taking down my whole machine now, which is an improvement over the last time I tried this with processes.
Post reply on HN