Python Threads - MultiThreading in Python and Python GIL - Python MultiProcessing

  Рет қаралды 19,132

Cognitive Programmer

Cognitive Programmer

Күн бұрын

Пікірлер: 84
@dimberabha2620
@dimberabha2620 3 жыл бұрын
This is what a developer wants. The difference you have shown is perfectly helpful. Thank you sir
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thanks a lot for your kind words… 🙏🙏🙏
@GrandTalkShow
@GrandTalkShow 2 ай бұрын
thats called content. truely under rated video.
@Cognitive-Programmer
@Cognitive-Programmer 2 ай бұрын
Thank you so much for your kind words 🙏
@ahshch
@ahshch Ай бұрын
well the best explanation of difference between multi threading and multi processing
@Cognitive-Programmer
@Cognitive-Programmer Ай бұрын
Thank you so much for your comment and appreciation 🙏
@raghvendramishra2862
@raghvendramishra2862 Жыл бұрын
Great !!!! I have gone through numerous texts and papers, and websites to clearly dig all these questions. But your one video gives answers for all of them. Thanks a lot Sir.
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
Thanks a lot for your comment. Glad to know that it helped 🙏
@Vijay-Yarramsetty
@Vijay-Yarramsetty Жыл бұрын
by far the most lucid explanation of threading vs multi processing in Python. Thanks very much.
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
Thank you so much 🙏
@Mina.f.a
@Mina.f.a 2 жыл бұрын
Amazing teaching skills ! Thank you for teaching me this very effectively two minutes before my interview !!!
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thanks for your comment. Glad that it was of some help. All the best for your interview 🙏
@classicaf
@classicaf Ай бұрын
Wow, pure joy to watch, loved it sir
@Cognitive-Programmer
@Cognitive-Programmer Ай бұрын
Thank you so much for your comment 🙏
@akashjain35
@akashjain35 2 жыл бұрын
Now this is what I call quality content. Subbed!
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thank you so much 🙏
@shubhashishsatpathy8736
@shubhashishsatpathy8736 Жыл бұрын
Great tutorial, really helpful. One question - at 8:26 not sure how setting kill_thread to True is picked up by the thread. If i were not using threading at all and had that while loop running infinitely, setting kill_thread to True later would not have stopped that loop. Why does it stop it for a thread?
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
Hello Thanks for your comment . The thread function is continuously checking kill_thread variable in every iteration, so whenever it will be true, it will be stop the thread Hope it helps Thanks
@shushens
@shushens 2 жыл бұрын
Really like this. I hope you keep making more videos like this one. Kintu mama, threading video gulo diye ekta playlist baniye dile khub bhalo hoto.
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thanks for your comment 🙏 Here is the playlist on Python Multithreading
@Parthiban_Straight_Edge
@Parthiban_Straight_Edge 2 жыл бұрын
Great explanation Daksh!! Keep it up
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thank you so Much 🙏
@sunilkoiri1030
@sunilkoiri1030 2 жыл бұрын
Awesome demo + explanation
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thank you so much for your comment 🙏
@mohitrathore8808
@mohitrathore8808 Жыл бұрын
Bestest Tutorial Ever
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
Thanks for your kind words 🙏
@DevendraSingh-xf6cn
@DevendraSingh-xf6cn 2 жыл бұрын
Great Content! Just a question, when you started 2 threads. They both remained in active state. I can understand as 1 thread is running on while loop (infinite) but the other should close after a certain sleep time which is not happening in your case. Please explain: M i missing something here?
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thanks for your comment. Sorry I might not have understood your question properly, but if you're talking about 2 threads I create (in ~9th minute of this video), then both threads are created using same function i.e. working_thread So the behaviour is expected. Hope it clarifies your doubt
@tejasarlimatti8420
@tejasarlimatti8420 2 жыл бұрын
amazing video
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thanks a lot for your comment 🙏
@pakado2009sp
@pakado2009sp 3 жыл бұрын
GREAT VIDEO!!!!!! WELL DONE!
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thank you so much for your comment 🙏🙏🙏
@468hitman
@468hitman Жыл бұрын
Very nicely explained
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
Thanks a lot for your comment 🙏
@Haririsina
@Haririsina 2 жыл бұрын
You explained it very clear thank you
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thanks for your comment 🙏
@PonnusamyK
@PonnusamyK 2 жыл бұрын
Thank you sir, Very usefull
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thanks for your comment 🙏
@temperkan3727
@temperkan3727 Жыл бұрын
Great video
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
Thank you so much for your comment 🙏
@Vijay-Yarramsetty
@Vijay-Yarramsetty Жыл бұрын
this is great content. I wish I found it long back.
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
Thanks a lot 🙏
@anaryz_supa2653
@anaryz_supa2653 2 жыл бұрын
Thanks! Helped a lot.
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thanks for your comment. Glad to know that it helped 🙏
@sanjaybhatikar
@sanjaybhatikar 2 жыл бұрын
Awesome, thank you!
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thanks for your comment 🙏
@aashishgoyal1436
@aashishgoyal1436 3 жыл бұрын
Amazing content sir. Please complete the series. It is really helpful
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thanks for your comment 🙏🙏🙏 sure I am planning to have more videos on this topic.. Thanks again
@kosgeivictor6146
@kosgeivictor6146 Жыл бұрын
Perfect explanation, thank you.
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
Thanks for your comment 🙏
@haneulkim4902
@haneulkim4902 Жыл бұрын
Thanks for great video. I have few questions: 1. Each thread takes up 100% CPU, my understanding is CPU_i refers to number of cores(i) then when 2 threads take up 100% of CPU_01, CPU_02 it means that in two cores it has one thread each which utilize all of its computation ability? 2. My goal is distribute training deep learning model using tensorflow. I need to check if it is multi-threading/multi-processing before moving onto multi-device distributed training, I am very new to linux systems therefore do not know how to check if tensorflow utilizes all CPU and does multi-threading/processing. Could you recommend me some courses or materials that will help me understand how to analyze CPU usage?
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
Hi Thanks for your comment. irrespective of the number of threads, only 1 CPU will be used. However, in case of Multi Processing, multiple CPU's can be used Hope it helps Thanks
@haneulkim4902
@haneulkim4902 Жыл бұрын
@@Cognitive-Programmer Thanks for the quick reply! I've edited my question, do you mind clarifying my understanding please?
@ajiteshsingh3764
@ajiteshsingh3764 3 жыл бұрын
Perfect explanation
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thanks a lot for your comment 🙏🙏🙏
@omkarmore2198
@omkarmore2198 3 жыл бұрын
Excellent
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thanks for your comment 🙏🙏🙏
@chebalid6797
@chebalid6797 Жыл бұрын
How would I determine the maximum numbers of threads a proccess can have in regards to the computer resources(RAm, cores etc)
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
It's a system limitation and not of the programming language.. You need to check your system parameters.
@chebalid6797
@chebalid6797 Жыл бұрын
@@Cognitive-Programmer Example I have a linux machine with following Architecture x86_64 CPU(s) : 4 Threads per core : 2 Core(s) per socket : 2 Sockets(s) :1 I have for example a python code, does it mean the most number of threads I can open on this specific code is 2(taking into account the main thread). Am confused about this yet I really want to have a firm understanding
@SodalisUK
@SodalisUK Жыл бұрын
You can have as many threads as you want, but only 1 that can actually be executing python instructions at any instant because of the GIL.
@popojamesforreal5667
@popojamesforreal5667 2 жыл бұрын
Nice video. Pretty helpful :)
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thank you 🙏
@tastaslim
@tastaslim 2 жыл бұрын
An Insightful Techie I have this doubt, are threads closed automatically by python? I mean what if I don't use join() function, will thread be closed and if yes how does it happen and is there any certain amount of time for that. If you answer it, It will help me a lot. Thank you
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Hello Thanks for your comment. A thread will close automatically when it completes. You don't need to explicitly wait for join, but its a good practice to make sure that all your threads are closed before your program / function terminates. Hope it helps. Thanks
@aleksandarpetrovic2632
@aleksandarpetrovic2632 3 жыл бұрын
Amazing explanation, tnx
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thanks a lot for your comment 🙏🙏🙏
@vigneshkumar6451
@vigneshkumar6451 2 жыл бұрын
Wonderful explanation sir. 🙂🙂 One small suggestion to run and show code using any IDE. Difficult to grab in jupyter notebook.. Expecting ML series from you. Thanks..
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thanks for your valuable feedback. 🙏
@ananyamahapatra6597
@ananyamahapatra6597 7 ай бұрын
Thank u so much Sir🙂
@Cognitive-Programmer
@Cognitive-Programmer 7 ай бұрын
Thank for your comment 🙏
@yt-1161
@yt-1161 Жыл бұрын
what is there wasn't GIL. would multi-threading and multi-processing be the same
@Cognitive-Programmer
@Cognitive-Programmer Жыл бұрын
In terms of doing CPU intensive task within a process - Loseley Yes, but from an operating system perspective a thread and process are different. for example, you don't need IPC to communicate between threads. Hope it helps. Thanks 🙏
@Aditya-ne4lk
@Aditya-ne4lk 2 жыл бұрын
maybe you should have explained what is the purpose of GIL, i understood what it does, but not why
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Thanks for your comment and suggestion. Without GIL, python will have to change completely as the current implementation will not run with GIL Hope it clarifies . Thanks again for your comment 🙏
@SodalisUK
@SodalisUK Жыл бұрын
The purpose of the GIL is to avoid the need for locking objects every time you want to use or change them. If thread 1 is doing x += 1 and thread 2 is doing x -= 1 then x should stay the same but if they both get x at the same time the result will be wrong. Python also keeps a count of the number of references to an object this way, and if this incorrectly drops to zero, and the object is garbage collected into free memory and the memory reused, all sorts of chaos would happen.
@SodalisUK
@SodalisUK Жыл бұрын
​@@Cognitive-ProgrammerThere is a genuine proposal for a version without the GIL based on a successful proof of concept. But this will still be years away.
@NS-te8jx
@NS-te8jx 3 жыл бұрын
you should keep your code on git and share links here, so that we could do quick experiments on our machines while watching the videos.. that would make it more attractive and practical
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thank you for your valuable suggestion.. will implement for later videos
@hiteshpandey3824
@hiteshpandey3824 3 жыл бұрын
Should have found you sooner.
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thank you 🙏 🙏🙏
@vickkyphogat
@vickkyphogat 3 жыл бұрын
hindi Please!!!!!!!!!!!!!!!!!!
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 1,7 МЛН
Multithreading in Python | Thread synchronisation and Locking
11:41
Cognitive Programmer
Рет қаралды 9 М.
Python is NOT Single Threaded (and how to bypass the GIL)
10:23
Jack of Some
Рет қаралды 110 М.
threading vs multiprocessing in python
22:31
Dave's Space
Рет қаралды 597 М.
Unlocking your CPU cores in Python (multiprocessing)
12:16
mCoding
Рет қаралды 311 М.
MultiThreading in Python | Python Concurrent futures | ThreadPoolExecutor
13:15
New Features You Need To Know In Python 3.12
12:04
ArjanCodes
Рет қаралды 183 М.
Python Metaclasses: Everything is an Object
31:23
Real Python
Рет қаралды 7 М.