Is it possible to have true parallelism in python due to the presence of GIL? As far as I know each thread acquires the GIL before executing while other threads wait until the GIL is released. Why have GIL if it is such a bottleneck
-
See [David Beazley's GIL research](http://www.dabeaz.com/GIL/) for lots of great info on this subject. – mshildt Jul 14 '16 at 12:54
2 Answers
Python, the language does not necessarily enforce GIL. It's the different implementations of the language which may or may not have GIL.
CPython (the de-facto implementation) has GIL. So you can not have truly parallel threads while you're using it. However, you can use multi processing to gain parallelism. PyPy, another implementation of the language also has GIL now.
There are other implementations of the Python language (Jython & IronPython for example) which do not have GIL and you can use threads to run parallel operations.
Cython has a GIL but you can release it using a with
statement.
Links of the projects mentioned:
More resources on this topic:
A question on programming stack exchange: https://softwareengineering.stackexchange.com/questions/186889/why-was-python-written-with-the-gil (Thanks to @Rogalski)
Python Wiki: https://wiki.python.org/moin/GlobalInterpreterLock
David Beazley's talk - https://www.youtube.com/watch?v=Obt-vMVdM8s
Article from Jeff Knupp : https://jeffknupp.com/blog/2013/06/30/pythons-hardest-problem-revisited/
-
-
http://programmers.stackexchange.com/questions/186889/why-was-python-written-with-the-gil – Łukasz Rogalski Jul 14 '16 at 12:54
-
1@FaizHalde: there are hundreds of articles about the topic on the web – Andrea Corbellini Jul 14 '16 at 12:54
-
Better interoperability with C code. For example look at the plethora of the popular libraries - numpy, scipy, pandas - they all have a significant portion of the codes written in C. – masnun Jul 14 '16 at 12:54
If you want to learn about the GIL in python, I'd suggest to start reading here:
https://wiki.python.org/moin/GlobalInterpreterLock
See the section Eliminating the GIL for an explanation why python still has the GIL.

- 6,131
- 4
- 24
- 44
-
1BTW: you'll find that information by googling "python gil" and clicking on the first result... Might have been faster than posting on SO... ;) – Felix Jul 14 '16 at 12:59