Live data from Hacker News

Let's Remove the Global Interpreter Lock

morepypy.blogspot.com

291–300 of 326 posts

Re: Let's Remove the Global Interpreter Lock

#291
Hi, blog post author here. Let me put an offer here:

If you want to ask a question that warrants a response (as opposed to promoting your own effort, which is valid but does not warrant a response), please mail me, the mail is public and I'll put the responses publically on either my blog or pypy blog.

Re: Let's Remove the Global Interpreter Lock

#292

Earlier quoted context omitted.

That's not the concern. Python already has threads and race conditions (although the GIL means that the interpreter itself probably won't get corrupted while executing a piece of bytecode). What python doesn't have is a C api for extensions that makes sense without a GIL. So ideally a correct threadsafe C extension will continue to be correct, which probably implies that a function called "PyEval_AcquireLock" will co…

C extensions will still run under the GIL

Given the amount of C extension code running in a typical large Python app these days, isn't this basically defeating the purpose?

Re: Let's Remove the Global Interpreter Lock

#293
post #97

Having ported Ruby to IBM's Blue Gene/L my advice is to forget about the GIL. Run one Python process per core. Use something like MPI2 for message passing communication. Ruthlessly eliminate bloat code from production binaries and statically link all the things.

I agree wholeheartedly. Almost every time I hear from someone who is upset about the GIL, I find that they would be much better suited to using multiprocessing instead of multithreading. With 80% of the developers out there, they are basically assured of producing better, more stable code this way.

If you have long running, computationally intensive code, with simple interactions, sure. Then multiple processes is the right thing.

But sometimes you are writing a GUI app, or some "real time" code [1]. You put blocking calls onto a different thread to keep the UI responsive. But then you find that still the blocking calls freeze the UI across threads due to the GIL.

Pure Python code is not the problem in this case - the GIL gets released between statements often enough. It is long running C code. You could release the GIL manually in there, but it is not done everywhere. Also, there are often calls that are supposed to be instant (like opening a file, or starting an async operation), that take seconds under bad conditions (when the network is down).

----

[1] well, with Python probably not in the strict definition of real time, but say you are controlling some external device

Re: Let's Remove the Global Interpreter Lock

#294
I just made a quick test: CPython-3.6.1 vs. Jython-2.7.0 (May 2015)

I ran Larry Hastings' Gilectomy testprogram x.py: fib(40) on 8 threads HW: MacBook Pro, 2015, 8 (4+4) cores, 1Gb RAM

Jython ran the program 8 times faster, utilising all 8 cores >95%. Python ran on 1-2 cores less than 60% utilisation. (Pretty sure Jython will run 16 times faster on 16 cores)

It's 2017, why this is acceptable to GvR and the Python community is beyond me.

Jython: real 1m4.959s user 7m38.521s sys 0m2.396s

Python: real 8m19.035s user 8m16.508s sys 0m11.424s

Re: Let's Remove the Global Interpreter Lock

#295
post #247

Earlier quoted context omitted.

Only if you know ALL of Perl. I used to carry around a Perl program of my own on a printout to take to VLSI interviews. That way when I got the "Do you know Perl?" question I could bring it out and force the interviewer into MY stupid subset of Perl rather than being stuck in his stupid subset of Perl. That's not a compliment to the language.

Is Python really any different or is it just wishful thinking? Why do I see Python programs that look like a weird mix of Lisp and Java? Surely it is because even with what Python enforce, there are many many ways to produce unclear code that really don't even has to do with the language used. And why did my employer see the need for the comprehensive Python style guidelines manual... I guess Python bit just as hard…

> Is Python really any different or is it just wishful thinking?

I'll stick my neck out and say that personally I feel that Python is actually better in this regard. Perl pissed me off so much that I left Perl at the height of its popularity. I probably had least 5 years(probably closer to 10+, but my memory of dates is fuzzy--pretty sure I never used Perl 3, though ...) years of professional use of Perl under my belt at that point.

I still migrated to Python.

That's a pretty big indictment when someone is willing to go back to being a n00b rather than continue to put up with continuing grief.

> Why do I see Python programs that look like a weird mix of Lisp and Java? Surely it is because even with what Python enforce, there are many many ways to produce unclear code that really don't even has to do with the language used.

The difference, from my experience, is that newbies in Python don't write code that A) other newbies can't understand and B) requires excessive mental effort from experienced folks to understand. Neither of those were true in my experience for Perl. A newb in Perl would very quickly trip something that would boggle even your local Perl expert.

I remember when I was a beginner and posted a 15 line program to comp.lang.perl and watched several of the experts actually wondering what the correct interpretation of the grammar was. I don't think I ever managed to cause something like that in Python. Obviously, I threw that program out post haste.

Sure, people can make amazingly complicated things with generators, decorators, etc once they get the hang of the language. However, newbies don't normally do this in Python. As you point out, they normally write it like Java (for better and worse).

In Perl, newbies immediately had to grapple with things like list vs scalar context and god help you if you tripped over a corner case (although, to be fair, God, in the form Randall Schwartz, WOULD quite often help you if you asked on comp.lang.perl ...)

> And why did my employer see the need for the comprehensive Python style guidelines manual... I guess Python bit just as hard as Perl.

I would personally expect that any company writing a very large quantity of code would produce a style guide for any language they use.

> The quality of Perl frameworks, libs, example code etc is actually increasing and getting easier to find.

That's actually really cool.

Re: Let's Remove the Global Interpreter Lock

#296

Earlier quoted context omitted.

>Memory consumption is bloated and the CPU caches thrash. Launching a subprocess is expensive Statically and dynamically loaded binaries are resident in the kernel's page cache. Which while each process will have different locations within its process address space for each process (b/c ALSR), they _should_ be de-duplicated in RAM, ultimately all these seperate in process images will be pointing at the same physical…

That's just the interpreter's executable. All the stuff that's generated from the Python code you load, and any data it generates, is unique to the process.

With Python that's a lot of stuff; I suggest running strace python some_small_script.py to see just how much data Python loads on every single startup.

Re: Let's Remove the Global Interpreter Lock

#297
post #234

Earlier quoted context omitted.

Lately I've found out that multiprocessing will not help you if your program is multithreaded. There is no sane way of forking a multithreaded program. For one, the child process will inherit a copy of all locks in the state they where at forking time, possibly causing random crashes and deadlocks.

> There is no sane way of forking a multithreaded program The sane way of forking a multithreaded process is to exec immediately after.

It is possible to do more after a fork (cf. async-signal-safe), but it's hairy enough to just say — don't, always exec (similar to how doing actual work in a signal handler is generally a very bad idea).

Re: Let's Remove the Global Interpreter Lock

#298

I just made a quick test: CPython-3.6.1 vs. Jython-2.7.0 (May 2015) I ran Larry Hastings' Gilectomy testprogram x.py: fib(40) on 8 threads HW: MacBook Pro, 2015, 8 (4+4) cores, 1Gb RAM Jython ran the program 8 times faster, utilising all 8 cores >95%. Python ran on 1-2 cores less than 60% utilisation. (Pretty sure Jython will run 16 times faster on 16 cores) It's 2017, why this is acceptable to GvR and the Python com…

Could you post the code for that fib program I couldn't find it anywhere.

Re: Let's Remove the Global Interpreter Lock

#299

Earlier quoted context omitted.

^This. It is a very common usecase for applications I work with to create a very large in memory read-only pd dataframe and then put a flask interface to operations on that dataframe using gunicorn and expose as an API. If I use async workers, the dataframe operations are bound by GIL restraints. If I use sync workers, each process needs a copy of the pd dataframe which the server cannot handle (I have never seen pre…

Tried a memmap?

I still wish to find a good tutorial about memmap. The doc about it is very formal. Something with clear use cases, patterns, gotchas and best practice would probably make it more popular.

Re: Let's Remove the Global Interpreter Lock

#300

Earlier quoted context omitted.

C extensions will still run under the GIL

Given the amount of C extension code running in a typical large Python app these days, isn't this basically defeating the purpose?

It really depends on the use case I think
Post reply on HN