Python 3.13: Multithreading without GIL restrictions is now a reality

Teacher

Professional
Messages
2,670
Reaction score
783
Points
113
Python rushes to new heights of performance for working with AI.

This is a landmark era in the world of programming: the main branch of Python has been introduced with code that promises to improve multithreading and concurrency in program execution.

The added code allows you to disable the Global Interpreter Lock — GIL), a key element in the implementation of CPython, the standard version of the Python programming language. The GIL was long considered an obstacle to efficient multithreaded code execution, as it prevented multiple threads from executing instructions at the same time.

The problem was particularly acute in computationally intensive tasks and the field of artificial intelligence, where the need for multithreading is particularly high. For example, DeepMind noted that many applications would like to use up to 100 threads per process, but due to the GIL, the possibilities were limited.

The changes proposed in PEP 703 (Python Enhancement Proposal) make the GIL optional in CPython and were adopted by the governing body for implementation in version 3.13. However, it emphasizes the importance of gradually implementing changes with the ability to roll back if serious problems are detected.

Disabling GIL is expected to introduce errors in existing code. For example, there have already been crashes during full testing with the GIL disabled. At the same time, work is underway to support extensions that require the GIL, which promises new features for developers without significant performance loss.

The innovation is met with optimism, because disabling the GIL can significantly improve the efficiency of working with AI models and improve multithreaded code execution. Python 3.13 is scheduled for release on October 1, 2024.
 
Top