Introduction
In most machine learning jobs, you won't do research on how to improve some model architecture or design a new loss function. Most of the time you should use what already exists and adapt it to your use case. That is why it is very important to optimize your project in terms of architectural design and implementation. It all starts from there: you want optimal, clean, reusable code that runs as fast as possible. Threading is a native library built into Python that people don't use as often as they should.
About threads
Threads are a form of program to split in two or more simultaneously (or pseudo-simultaneously) executing tasks …in general, a thread is contained within a process and different threads in the same process share the same resources.
We don't talk about multiprocessing in this article, but the Python library for multiprocessing works very similarly to multithreading. In general:
- Multithreading is great for I/O bound tasks, such as calling an API inside a for loop.
- Multiprocessing is used for CPU-bound tasks, such as…