Level Up Your Coding Skills with Python Threading | by Marcello Politi | Nov, 2024


Photo by Sonika Agarwal on Unsplash

Learn how to use queues, daemon threads, and events in a Machine Learning project

Introduction

In most Machine Learning jobs, you won’t do research on improving some model architecture or designing a new loss function. Most of the time you must utilize what already exists and adapt it to your use case. So it is very important to optimize your project in terms of architectural design and implementation. Everything starts from there: you want optimal code, that is clean, reusable and runs as fast as possible. Threading is a Python built-in native library that people don’t use as often as they should.

About Threads

Threads are a way for a program to split itself into two or more simultaneously (or pseudo-simultaneously) running tasks … in general, a thread is contained inside a process and different threads in the same process share the same resources.

In this article, we don’t talk about multiprocessing, but the Python library for multiprocessing works very similarly to the multithreading one. In general:

  • Multithreading is great for I/O bounds tasks, like calling an API within a for loops
  • Multiprocessing is used for CPU-bound tasks, like…

Recent Articles

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here