Blog

python tutorials and learn python

Created with Sketch.

Python Event Loop

Python Event Loop Summary: in this tutorial, you’ll learn about the Python event loop and how Python uses it to achieve the concurrency model using a single thread. Introduction to the Python event loop Concurrency means multiple tasks can run at the same time. The asyncio built-in package allows you to run tasks concurrently using…
Read more

Python ProcessPoolExecutor

Python ProcessPoolExecutor Summary: in this tutorial, you’ll learn how to use the Python ProcessPoolExecutor to create and manage a process pool effectively. Introduction to the Python ProcessPoolExecutor class In the previous tutorial, you learned how to create running code in parallel by creating processes manually using the Process class from the multiprocessing module. However, manually…
Read more

Python Multiprocessing

Python Multiprocessing Summary: in this tutorial, you’ll learn how to run code in parallel using the Python multiprocessing module. Introduction to the Python multiprocessing Generally, programs deal with two types of tasks: I/O bound tasks: if a task does a lot of input/output operations, it’s called I/O-bound tasks. Typical examples of I/O-bound tasks are reading…
Read more

How to use the Python Threading Lock to Prevent Race Conditions

How to use the Python Threading Lock to Prevent Race Conditions Summary: in this tutorial, you’ll learn about the race conditions and how to use the Python threading Lock object to prevent them. What is a race condition? A race condition occurs when two threads try to access a shared variable simultaneously. The first thread…
Read more

Python ThreadPoolExecutor

Python ThreadPoolExecutor Summary: in this tutorial, you’ll learn how to use the Python ThreadPoolExecutor to develop multi-threaded programs. Introduction to the Python ThreadPoolExecutor class In the multithreading tutorial, you learned how to manage multiple threads in a program using the Thread class of the threading module. The Thread class is useful when you want to…
Read more

Python Thread-safe Queue

Python Thread-safe Queue Summary: in this tutorial, you’ll learn how to use a synchronized queue to exchange data safely between multiple threads. Introduction to the Python thread-safe queue The built-in queue module allows you to exchange data safely between multiple threads. The Queue class in the queue module implements all required locking semantics. Creating a…
Read more

Python Daemon Threads

Python Daemon Threads Summary: in this tutorial, you’ll learn about Python daemon threads and how to use them effectively. Introduction to the Python daemon threads In Python, every program has at least one thread called the main thread. To create a program that has more than one thread, you use the threading module. By using multiple threads…
Read more

Python Multithreading Example

Python Multithreading Example Summary: in this tutorial, you’ll learn how to use the Python threading module to develop a multithreaded program. Inheriting from the Thread class We’ll develop a multithreaded program that scraps the stock prices from the Yahoo Finance website. To do that, we’ll use two third-party packages: requests – to get the contents…
Read more

Python Threading

Python Threading Summary: in this tutorial, you’ll learn how to use the Python threading module to develop multi-threaded applications. Single-threaded applications Let’s start with a simple program: from time import sleep, perf_counter def task(): print(‘Starting a task…’) sleep(1) print(‘done’) start_time = perf_counter() task() task() end_time = perf_counter() print(f’It took {end_time- start_time: 0.2f} second(s) to complete.’)…
Read more

What are the Differences between Processes and Threads

What are the Differences between Processes and Threads Summary: in this tutorial, you’ll learn about the processes and threads, and more importantly, the main differences between them. Introduction to processes and threads Suppose that you have a simple Python program: x = 10 y = 20 z = x + y   Computers don’t understand…
Read more