4

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

ffff
  • 2,853
  • 1
  • 25
  • 44
  • 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 Answers2

9

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:

Community
  • 1
  • 1
masnun
  • 11,635
  • 4
  • 39
  • 50
1

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.

Felix
  • 6,131
  • 4
  • 24
  • 44
  • 1
    BTW: 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