Writing Performant Parallel Python Code

Distinguish IO-bound and CPU-bound applications in Python to write code that runs faster

Thiago Candido
The Startup

--

Image from MonikaP by Pixabay

In what cases is the use of libraries for concurrent application development appropriate and can result in increased performance using Python?

Python Interpreter

To answer this question, we first need to discuss how the Python interpreter works. In the course of the story, when detailing how the interpreter works, we will be referring to CPython, which brings the reference implementation of the Python language and is also the standard and most used interpreter among developers.

CPython is the reference interpreter, created by Guido van Rossum, creator of the Python language. With the popularization of the language, other interpreters were created by the community, such as IronPython (.NET), Jython (JVM), PyPy, Stackless, etc.

When executing the code, the interpreter uses a security mechanism called GIL, or Global Interpreter Lock. This lock structure was originally implemented to eliminate problems related to memory management in competing application scenarios. To execute the interpreter's instructions, it is necessary to obtain control of the GIL by the thread.

Locks are one synchronization

--

--

Thiago Candido
The Startup

I help people to use their products and services data intelligently @eximiaco