The Python programming language has been criticized for its inability to thread across cores due to the Global Interpreter Lock (GIL). This limitation has led to Python lagging behind its peers in terms of speed and efficiency. However, with the recent acceptance of PEP 703, it seems that Python’s GIL removal might finally happen. But is this really a good idea?
Removing the GIL would change the assumption of safe, single-threaded execution that every piece of Python code written for the CPython interpreter relies on. This would require a massive overhaul of existing Python projects, with many libraries and programs needing to be retested and potentially rewritten. The transition would be a nightmare for open-source projects, which would have to maintain two codebases: one for GIL-based runtimes and another for where Python’s GIL is removed.
Furthermore, the removal of the GIL would have far-reaching consequences beyond the boundaries of Python’s interpreter. Python is often used to format and massage input data, which is then fed to functions and routines implemented in languages such as C++ or Java that are more capable of threading across cores. These functions expect to be invoked in a safe and single-threaded manner, and would require extra tests, updates, and dual maintenance as well.
The removal of the GIL would be a poison pill that would kill off Python as we know it. It would force developers to choose between maintaining two codebases or abandoning Python altogether. This is not a new scenario; we’ve seen it before with the fumbled switch from Python 2 to Python 3, when the stewards of the Python language turned their backs on the community and abandoned backwards compatibility.
Fortunately, there are alternatives to Python that can provide a smoother transition. Mojo, a programming language that fully supports Python syntax, can run multiple times faster than Python and is designed to work across the entire AI stack. With Mojo, developers can write C and C++ functions that can be used to support multi-threaded Python code, and many popular open-source machine-learning libraries are already ported to Mojo.
In conclusion, removing the GIL would be a mistake that would have devastating consequences for the Python community. It’s time to consider alternative languages like Mojo that can provide a more efficient and professionally maintained solution.
Mojo: The future of AI and ML development
The limitations of Python’s performance
Rust: A fast and memory-safe alternative to Python