MultiThreading in Python | Creating and Managing Python Threads | Python Threading Tutorial

preview_player
Показать описание
In python, even with the availability of Global Interpreter Lock (GIL) we can create threads and make use of them especially in non CPU intensive jobs. To create python threads we need to include threading module of the python and use the Thread class of the python threading module.

In this video, I've explained what are thread entry point functions and how you can create python threads using the built in Thread class. I've also talked about how to start the thread using the thread start function and waiting for the thread to finish using the thread join function.

Along with creation of threads, I've also explained how we can give a custom user defined name to a python thread and how to use python thread functions like is_alive. You'll also learn about the usage of python thread identity and how to use it to find interesting information like whether the thread had run previously or not.

After this, you'll learn about passing one or multiple parameters to the thread function and how to make use of the same.

The last topic of this video is about creating a python thread in an object oriented way where we subclass the python Thread class and create a run function with the implementation. The way to share the parameter is different with subclassing and I've also talked about the same.

I hope and believe that this video will help you in your learn journey of Python Programming. Here are the contents of this video.

Timecodes
0:00 : Python Threads and Multithreading in python
0:50 : Python threads topic I'll cover in this video
1:08 : Python threading module and the Thread class
1:38 : Python Thread entry point function - The thread function
2:29 : Creating a python thread
2:46 : Parameters of python Thread class
3:37 : Starting a python thread - The python thread is_alive and start function
4:46 : Naming of Thread in python
5:48 : Python thread joins - Joining the thread in python
6:40 : Python Thread Identity and how to use it
7:38 : How to check if the python thread is already started and finished
8:27 : Passing arguments to the python thread
9:20 : Passing multiple arguments in a thread function
9:38 : Python threads by subclassing Thread class
10:37 : Python Thread run function
11:12 : Python thread parameters with subclassing Thread class

#python #multithreading #multicore #cpu #pythonprogramming

About Me i.e. An Insightful Techie

Greetings and Thanks a lot for checking out my YouTube Channel. I’m Deepak K Gupta (Daksh). This channel is a medium for me to share my learnings and journey as a Techie so that you not only learn from my experience but also from my mistakes

As a techie I am closely associated with software development, so most of my content will revolve around Programming Languages, AI, Machine learning and Databases. I share things which will help you learn, remember and use these things in an effective and efficient way.

As a Techie, I also know that there is a life beyond software development and it has a profound impact on our career as well as on our well being. I also share those learnings which I feel are worth sharing with the intention that it MAY help you in taking better decisions in your life.

Last but not the least, I'm a traveler and explorer by nature. I would like to take you with me on some of the interesting journeys around the world. Believe me there is more to learn outdoors than indoors

Hope you’ll like my contents and will be part of my journey 🙏

Рекомендации по теме
Комментарии
Автор

I wish I had teacher like you during my college time, made complex concept so easy. thank you so much

dvivuje
Автор

why do you need that super()__init__() method inside init ? @10:25

yt-
Автор

Someone to assist. I am having issue with a socket. This is the output I get:
Line 683: in process_request_thread self.finish_request(request, client_address) this is my code below:

try:
self.finish_request(request, client_address)
except Exception:
self.handle_error(request, client_address)
finally:


Can anyone tell me what is to be corrected?

lynsonrozar
Автор

Hey bro, how can I store all threads? I have created a sub class of thread. It has some variable which updates every seconds. I want to store all threads and get any of them and print/use that variable

mariamkhanam
Автор

A same function in a for loop(within function def.) should be run in multiple thread..is it possible sir??

sujatabasu
Автор

Near 11:25, is there some magic where the Thread base class automagically understand that self.param1 should be used on initialization to define args=()? I guess I expected you to still have to pass param1 into Thread's args somehow. Super helpful video!

DanGitschooldude
Автор

what is the name of editor that you are using?

vkgaming
Автор

you can create a thread with a function that just while True:, so the main program ends but the thread never ends...good to make viruses.

bradenbigham