QUICK TIP
CONCURRENCY VS PARALLELISM
QUICK TIP
GLOBAL INTERPRETER LOCK (GIL)
The official documentation site of asyncio can be found at https://docs. python.org/3/ library/asyncio. html. You can also learn more information about asyncio at https://docs. python.org/3/ library/asynciodev.html and at https:// realpython. com/async-iopython.
It’s a common misconception that concurrency is the same thing as parallelism. Parallelism is the simultaneous execution of multiple entities of some kind, whereas concurrency is a way of structuring your components so that they can be executed independently.
A program’s development process should take into account the use of asyncio in order to properly design the application. The extra care and extra code that you write is the price you pay for faster execution time. Bear in mind that not everything can be executed concurrently
Because Global Interpreter Lock (GIL) is a part of Python and the way Python works, it’s good to learn more about it. GIL is a mutex (mutual exclusion variable) that permits only a single thread to hold the control of the Python interpreter. Put simply, this means that at every single moment only a single thread can be executed in Python. In a world with multiple CPUs and cores, this is not good.
OUR EXPERT
It’s only when you build software components concurrently that you can safely execute them in parallel, when and if your operating system and your hardware permit it. The Erlang programming language (www.erlang.org) did this a long time ago – long before CPUs had multiple cores and computers had lots of RAM.
So you might ask why do we need GIL. The main reason is to prevent deadlocks, which is a serious issue in multi-threaded programming. The second reason is that back in the first days of Python, computers didn’t have multiple cores, so using GIL wasn’t an issue back then. The main reason that GIL hasn’t been removed from the language is that this would create a lot of backward incompatibility issues, which in a language as popular as Python would be a huge issue.