Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

CPython the implementation has a GIL; Python the language does not. Plenty of other implementations (PyPy, Jython, Cython) avoid having a GIL or have options to disable it.

> If you wanted extreme performance Python is a lousy choice in the first place.

Using Python for glue code and C-modules for performance critical work is a popular option.



I'm aware of that, but CPython is by far the most popular implementation. Add IronPython to the list without a GIL as well.

However, Jython, IronPython and PyPy must all variously slow down even single-threaded code without the GIL because Python having the GIL made lists, dicts, and sets threadsafe. The locking (or complex lock-free algorithms or STM in the case of PyPy) is not free.

The Python language is just a poor choice for concurrency. It's also a poor choice for a glue language, as Lua is much better designed for that, but Python seems to have become popular in that role anyway (likely due to a richer ecosystem.) Python, even with all of PyPy's JIT magic is still one of the slower languages. If you're using it for real work (not just as glue) and you need extreme performance, then it's a poor choice in the first place.

Keep in mind that I have a Python day job, and Python has been my favorite language for over a decade. I'm not hating on Python, I'm just acknowledging its failings.


Through Cython you can write extensions that release the GIL to make them easily parellizable. However, given that I mostly work Python in Windows (and 64 bit version), I get that Cython might not be a viable option for your use cases.

As for high performance Python, I always recommend Ian Ozsvalds talks at various conferences. Python can be used to reach high performance, even work well in distributed environments and very paralell architectures. It's owed to the great librarys that were developed to work in those circumstances (Numpy, numba, SciPy, OpenCV[1], to name a few), but it's still something posible within the language. Add that to the rapid development cycle that is posible within it, and the flexibility that it can achieve, and you've got a great language for HPC -- despite it's shortcommings.

[1] I will acknowledge here that OpenCV is not Python-specific, if anyone wishes to point that.


I'll grant you all of those points, if you use Cython to compile your code to native or use a native library to do the expensive parts of your code, then it works out fine. Both of those get around Python's inherit slowness by doing the costly things outside of Python.


Cython isn't a separate implementation: it's merely a language that compiles down to CPython API calls. Therefore, it's bound by the GIL insofar as CPython extensions are.

PyPy does really have a GIL, it's only the experimental PyPy-STM which doesn't.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: