An Introduction to Multi-Threading

An Introduction to Multi-Threading

An Introduction to Multi-Threading. I thought we'd open up the boxes for a while just to see what these two mean. Sit back, take a coffee, and lets fire up those neurons.

A post or so ago, we had a discussion on the differences between multi-threading and multi-processing, this being a result of IronPython's feature to allow multi-threaded code to use multi-core processors. So in this article, I thought we'd open up the boxes for a while just to see what these two mean. Sit back, take a coffee, and lets fire up those neurons.

Background Check

Now, for an understanding of the concepts, we should differentiate between a process and a thread.

Process

Say I write a program: 

sample_prog.py. Once I ran this and let it do what it does best, I have created an instance of the program. In definition, this is a process.

To break this even further, if my program 

sample_prog.pywas, say, taking multiple files, editing the title of these files, and moving them in a different directory once processed, I would have broken the process down to threads. In this case, I have two threads:

  • Read the file and change the title within it.
  • Copy this file into a different directory of processed files.

Don't get it wrong, this is the same program instance(also called process) doing different things.

If we were to come back to something closer to home, you have opened a tab on Hacker Noon right now, while at the same time, I assume, have another tab open locked into your favourite ecommerce site.

In this case, you have one program running, your Firefox browser as a program (Of course, it's not Internet explorer open, is it?); this is the instance, that is, a process.

With this process, you have two tabs, in essence, two threads of the same process.

python multithreading memory-management memory-allocation threads task-management programming coding

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Calculate Memory Consumption of Python Code

Calculate Memory Consumption of Python Code - Python developers should be aware about the memory consumption of the code they are writing.This will help in multiple ways.Be it deciding…

Guide to Python Programming Language

Guide to Python Programming Language

Generate QR Code using Python — Python Programming — PyShark

This article will explore how to generate QR code in Python and some useful creation features from pyqrcode library. QR codes recently became more popular than ever before, yet few people know that the first iterations of QR codes were created back in 1990s in Japan for the automotive industry.

Python Programming: A Beginner’s Guide

Python is an interpreted, high-level, powerful general-purpose programming language. You may ask, Python’s a snake right? and Why is this programming language named after it?

Python Hello World Program - Create & Run Your First Python Program in PyCharm

Python Hello World Program - Your first step towards Python world. Learn how to create the Hello World Python program in PyCharm.