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

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ธ.ค. 2024

ความคิดเห็น • 84

  • @dimberabha2620
    @dimberabha2620 3 ปีที่แล้ว +10

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

  • @GrandTalkShow
    @GrandTalkShow 3 หลายเดือนก่อน +2

    thats called content. truely under rated video.

  • @Mina.f.a
    @Mina.f.a 2 ปีที่แล้ว +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 🙏

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

  • @akashjain35
    @akashjain35 2 ปีที่แล้ว +2

    Now this is what I call quality content. Subbed!

  • @Vijay-Yarramsetty
    @Vijay-Yarramsetty ปีที่แล้ว

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

  • @classicaf
    @classicaf หลายเดือนก่อน +1

    Wow, pure joy to watch, loved it sir

  • @ahshch
    @ahshch 2 หลายเดือนก่อน +2

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

    • @Cognitive-Programmer
      @Cognitive-Programmer  2 หลายเดือนก่อน

      Thank you so much for your comment and appreciation 🙏

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

  • @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 ปีที่แล้ว +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

  • @Haririsina
    @Haririsina 2 ปีที่แล้ว +1

    You explained it very clear thank you

  • @Parthiban_Straight_Edge
    @Parthiban_Straight_Edge 2 ปีที่แล้ว +1

    Great explanation Daksh!! Keep it up

  • @mohitrathore8808
    @mohitrathore8808 ปีที่แล้ว

    Bestest Tutorial Ever

  • @sunilkoiri1030
    @sunilkoiri1030 2 ปีที่แล้ว +1

    Awesome demo + explanation

  • @Vijay-Yarramsetty
    @Vijay-Yarramsetty ปีที่แล้ว

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

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

  • @kosgeivictor6146
    @kosgeivictor6146 ปีที่แล้ว

    Perfect explanation, thank you.

  • @anaryz_supa2653
    @anaryz_supa2653 2 ปีที่แล้ว +1

    Thanks! Helped a lot.

    • @Cognitive-Programmer
      @Cognitive-Programmer  2 ปีที่แล้ว

      Thanks for your comment. Glad to know that it helped 🙏

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

  • @pakado2009sp
    @pakado2009sp 3 ปีที่แล้ว +1

    GREAT VIDEO!!!!!! WELL DONE!

  • @468hitman
    @468hitman ปีที่แล้ว +1

    Very nicely explained

  • @ajiteshsingh3764
    @ajiteshsingh3764 3 ปีที่แล้ว +1

    Perfect explanation

  • @PonnusamyK
    @PonnusamyK 2 ปีที่แล้ว +1

    Thank you sir, Very usefull

  • @sanjaybhatikar
    @sanjaybhatikar 2 ปีที่แล้ว +1

    Awesome, thank you!

  • @popojamesforreal5667
    @popojamesforreal5667 2 ปีที่แล้ว +1

    Nice video. Pretty helpful :)

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

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

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

  • @temperkan3727
    @temperkan3727 ปีที่แล้ว +1

    Great video

  • @aleksandarpetrovic2632
    @aleksandarpetrovic2632 3 ปีที่แล้ว +1

    Amazing explanation, tnx

  • @ananyamahapatra6597
    @ananyamahapatra6597 8 หลายเดือนก่อน

    Thank u so much Sir🙂

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

  • @omkarmore2198
    @omkarmore2198 3 ปีที่แล้ว +1

    Excellent

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

  • @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 3 ปีที่แล้ว +1

    Should have found you sooner.

  • @vickkyphogat
    @vickkyphogat 3 ปีที่แล้ว

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