Achieving multithreading with Python


Python has GIL (Global Interpreter Lock) that allows only one thread to hold control of the Python interpreter. If a program is running on single-core having a single thread, then the impact is not visible to developers, but when it is run on a multicore system, GIL becomes a bottleneck as only one thread can run on a particular core even the other cores thread can be run in parallel.

Python 3.7 provides concurrent.futures module, which can be used to achieve multiprocessing and multithreading.

Python program can be of two types: I/O bound and CPU bound. CPU bound programs require heavy computation and need most of the CPU time to execute the instructions. On the other hand, I/O bound processes mostly communicate with the I/O devices like a disk, external drives, network communication, etc. i.e CPU remains idle during this period.

This nice article written by Sonu Sharma on Medium explains in details with examples the way to proceed.



Olivier Blerot, Director