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

Поділитися
Вставка
  • Опубліковано 6 лис 2024

КОМЕНТАРІ • 82

  • @dimberabha2620
    @dimberabha2620 3 роки тому +9

    This is what a developer wants. The difference you have shown is perfectly helpful. Thank you sir

  • @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.

  • @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  Рік тому

      Thanks for your comment. Glad that it was of some help. All the best for your interview 🙏

  • @Vijay-Yarramsetty
    @Vijay-Yarramsetty Рік тому

    by far the most lucid explanation of threading vs multi processing in Python. Thanks very much.

  • @GrandTalkShow
    @GrandTalkShow Місяць тому +1

    thats called content. truely under rated video.

  • @ahshch
    @ahshch 16 днів тому +1

    well the best explanation of difference between multi threading and multi processing

  • @shushens
    @shushens 2 роки тому +1

    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

  • @akashjain35
    @akashjain35 2 роки тому +2

    Now this is what I call quality content. Subbed!

  • @DevendraSingh-xf6cn
    @DevendraSingh-xf6cn 2 роки тому +1

    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

  • @vigneshkumar6451
    @vigneshkumar6451 2 роки тому +1

    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..

  • @aashishgoyal1436
    @aashishgoyal1436 3 роки тому +1

    Amazing content sir. Please complete the series. It is really helpful

    • @Cognitive-Programmer
      @Cognitive-Programmer  3 роки тому +1

      Thanks for your comment 🙏🙏🙏 sure I am planning to have more videos on this topic.. Thanks again

  • @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

  • @Haririsina
    @Haririsina 2 роки тому +1

    You explained it very clear thank you

  • @Vijay-Yarramsetty
    @Vijay-Yarramsetty Рік тому

    this is great content. I wish I found it long back.

  • @Parthiban_Straight_Edge
    @Parthiban_Straight_Edge 2 роки тому +1

    Great explanation Daksh!! Keep it up

  • @sunilkoiri1030
    @sunilkoiri1030 2 роки тому +1

    Awesome demo + explanation

  • @mohitrathore8808
    @mohitrathore8808 Рік тому

    Bestest Tutorial Ever

  • @PonnusamyK
    @PonnusamyK 2 роки тому +1

    Thank you sir, Very usefull

  • @kosgeivictor6146
    @kosgeivictor6146 Рік тому

    Perfect explanation, thank you.

  • @468hitman
    @468hitman Рік тому +1

    Very nicely explained

  • @anaryz_supa2653
    @anaryz_supa2653 2 роки тому +1

    Thanks! Helped a lot.

  • @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 роки тому +1

    Perfect explanation

  • @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.

  • @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

  • @tejasarlimatti8420
    @tejasarlimatti8420 2 роки тому +1

    amazing video

  • @sanjaybhatikar
    @sanjaybhatikar 2 роки тому +1

    Awesome, thank you!

  • @pakado2009sp
    @pakado2009sp 2 роки тому +1

    GREAT VIDEO!!!!!! WELL DONE!

  • @temperkan3727
    @temperkan3727 11 місяців тому +1

    Great video

  • @popojamesforreal5667
    @popojamesforreal5667 2 роки тому +1

    Nice video. Pretty helpful :)

  • @Aditya-ne4lk
    @Aditya-ne4lk 2 роки тому +1

    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 Рік тому +1

      ​@@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.

  • @omkarmore2198
    @omkarmore2198 2 роки тому +1

    Excellent

  • @aleksandarpetrovic2632
    @aleksandarpetrovic2632 3 роки тому +1

    Amazing explanation, tnx

  • @yt-1161
    @yt-1161 Рік тому

    what is there wasn't GIL. would multi-threading and multi-processing be the same

    • @Cognitive-Programmer
      @Cognitive-Programmer  11 місяців тому

      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 🙏

  • @ananyamahapatra6597
    @ananyamahapatra6597 6 місяців тому

    Thank u so much Sir🙂

  • @NS-te8jx
    @NS-te8jx 3 роки тому +1

    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 2 роки тому +1

    Should have found you sooner.

  • @vickkyphogat
    @vickkyphogat 3 роки тому

    hindi Please!!!!!!!!!!!!!!!!!!