gil

Which functions release the GIL in Python?

Which functions release the GIL in Python? Question: I found this sentence about GIL on the Python wiki: Luckily, many potentially blocking or long-running operations, such as I/O, image processing, and NumPy number crunching, happen outside the GIL. Is there a list of functions outside the GIL (at least in Python standard libraries)? Or how …

Total answers: 1

How can I check if a thread holds the GIL with sub-interpreters?

How can I check if a thread holds the GIL with sub-interpreters? Question: I am working on some changes to a library which embeds Python which require me to utilize sub-interpreters in order to support resetting the python state, while avoiding calling Py_Finalize (since calling Py_Initialize afterwards is a no-no). I am only somewhat familiar …

Total answers: 1

Why does this Python code with threading have race conditions?

Why does this Python code with threading have race conditions? Question: This code creates a race condition: import threading ITERS = 100000 x = [0] def worker(): for _ in range(ITERS): x[0] += 1 # this line creates a race condition # because it takes a value, increments and then writes # some inrcements can …

Total answers: 2

Can you race condition in Python while there is a GIL?

Can you race condition in Python while there is a GIL? Question: My understanding is that due to the Global Interpreter Lock (GIL) in cPython, only one thread can ever be executed at any one time. Does this or does this not automatically protected against race conditions, such as the lost update problem? Asked By: …

Total answers: 1

Green-threads and thread in Python

Green-threads and thread in Python Question: As Wikipedia states: Green threads emulate multi-threaded environments without relying on any native OS capabilities, and they are managed in user space instead of kernel space, enabling them to work in environments that do not have native thread support. Python’s threads are implemented as pthreads (kernel threads), and because …

Total answers: 2

numpy and Global Interpreter Lock

numpy and Global Interpreter Lock Question: I am about to write some computationally-intensive Python code that’ll almost certainly spend most of its time inside numpy‘s linear algebra functions. The problem at hand is embarrassingly parallel. Long story short, the easiest way for me to take advantage of that would be by using multiple threads. The …

Total answers: 3

What is the global interpreter lock (GIL) in CPython?

What is the global interpreter lock (GIL) in CPython? Question: What is a global interpreter lock and why is it an issue? A lot of noise has been made around removing the GIL from Python, and I’d like to understand why that is so important. I have never written a compiler nor an interpreter myself, …

Total answers: 8

Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad?

Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad? Question: I’m hoping someone can provide some insight as to what’s fundamentally different about the Java Virtual Machine that allows it to implement threads nicely without the need for a Global Interpreter Lock (GIL), while Python necessitates such …

Total answers: 5

Python Global Interpreter Lock (GIL) workaround on multi-core systems using taskset on Linux?

Python Global Interpreter Lock (GIL) workaround on multi-core systems using taskset on Linux? Question: So I just finished watching this talk on the Python Global Interpreter Lock (GIL) http://blip.tv/file/2232410. The gist of it is that the GIL is a pretty good design for single core systems (Python essentially leaves the thread handling/scheduling up to the …

Total answers: 7