4 ms·
If you are CPU-bound in pure Python code you’ve already lost. However, most of the time you’re doing CPU-heavy tasks in Python you’re likely using libraries th
by CrLf 5y ago
If you are CPU-bound in pure Python code you’ve already lost.
However, most of the time you’re doing CPU-heavy tasks in Python you’re likely using libraries that are ultimately implemented in another language for performance. The GIL can be (and is) released in those cases. Not much of a problem there.
It’s also released when you’re waiting for I/O. Not much of a problem there either.
Fear of the GIL have never stopped me from using threading in Python, and it has never been much of a problem. In the rare occasions I’ve noticed, I was doing something wrong, not using the appropriate library, or both. Or it might be the case that Python was just a poor choice for the problem, no matter how flexible it is.
I also wonder what would happen if CPython got rid of the GIL. Python has certain characteristics that make it hard to have a parallel interpreter, and people have tried (and failed) to remove te GIL before.
Don’t fear the GIL.