Grumpy: Go running Python! by Google

248 comments · 92% upvoted · source · other discussions

comments

semi_colon

As someone who doesn't use Go or Python: what is the use for this?

vplatt

To run Python code as a Go compiled executable. This allows them to avoid the Python Global Interpreter Lock (which severely limits Python's scalability within a single process) and run the Python code using Go modules as if they were Python modules.

Really, unless you're Google or another Python shop interesting in moving to Go, you probably don't have a use for this.

MightyCreak

Does this mean that you can't interpret two Python scripts at the same time because of GIL, but once interpreted, they can run in parallel?

ShotgunToothpaste

The global interpreter lock exists on a per-process basis in Python. Any two python scripts (including two instances of the same script) can be run in two different processes and do whatever. However, if one script starts multiple threads, only one thread will execute concurrently (the thread which has the interpreter lock).

This is a CPython implementation detail, and other Python runtimes need not have this limitation. The reason for GIL is because CPython's memory management is not thread-safe.

https://wiki.python.org/moin/GlobalInterpreterLock

btgeekboy

To add to this, there is a project to remove the GIL from CPython. However, it's not currently as fast as with the GIL. More info: https://lwn.net/Articles/689548/

[deleted]

[deleted]

fireflash38

Meaning threading will work just fine for network operations for the most part. It will perform worse than single threaded if doing something like simple math operations (like in the chart of the Fibonacci performance in the article).

ShotgunToothpaste

Ahh, I wasn't aware that Python allowed for system calls to be multi-threaded outside of the GIL's constraints but that makes sense.

I assume that means GIL is released before making a system call, and re-acquired before continuing after it completes?

MightyCreak

Thanks for this answer!