Python Threading Explained in 8 Minutes

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ม.ค. 2023
  • Today we will cover the fundamentals of multi-threading in Python in under 10 Minutes.
    ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
    📚 Programming Books & Merch 📚
    🐍 The Python Bible Book: www.neuralnine.com/books/
    💻 The Algorithm Bible Book: www.neuralnine.com/books/
    👕 Programming Merch: www.neuralnine.com/shop
    🌐 Social Media & Contact 🌐
    📱 Website: www.neuralnine.com/
    📷 Instagram: / neuralnine
    🐦 Twitter: / neuralnine
    🤵 LinkedIn: / neuralnine
    📁 GitHub: github.com/NeuralNine
    🎙 Discord: / discord
    🎵 Outro Music From: www.bensound.com/
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @ZettaBlitz
    @ZettaBlitz ปีที่แล้ว +23

    Your tutorial saved me man, it was so simple to follow through and understand when lots other articles that I've looked through couldn't, keep it up!

    • @Nik-rx9rj
      @Nik-rx9rj หลายเดือนก่อน

      Agreed! They overcomplicate the concepts and explain too much right away

  • @sarys5169
    @sarys5169 6 หลายเดือนก่อน +5

    bro, what is amazing about your content is that you are able to explain complicated concepts with simple jargon. great job.

  • @ExcelTutorials1
    @ExcelTutorials1 ปีที่แล้ว +4

    This is very very helpful. You did a great job explaining this. Thank you!!

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

    Great explanation, thank you! Gives the answer and the reason why threading might be used (when you have multiple things you want to check without stopping and waiting for one item to complete first)

  • @ricardokers
    @ricardokers ปีที่แล้ว +6

    Great video, congratulations. I'm from Brazil and your videos are helping me to deepen my knowledge in Python, thank you.

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

    You have the best coding tutorials on TH-cam.
    * clearly visible code
    * clear audio
    * clean, simple edits
    * pretty sure your intro has me Pavlov'd into focus mode

    • @Nik-rx9rj
      @Nik-rx9rj หลายเดือนก่อน +1

      I miss the normal indicators of a coding tutorial though: fan noises, poor quality audio, and a thick accent that makes learning nearly impossible

  • @ryun_d3v
    @ryun_d3v ปีที่แล้ว +15

    Much better than other tutorials that take longer and are more difficult to understand! Good job. Thanks!

  • @xiaoyangshawnhuang1251
    @xiaoyangshawnhuang1251 11 หลายเดือนก่อน

    simplicity makes you shine, thank you so much for the sharing. well done.

  • @A.Ventin
    @A.Ventin ปีที่แล้ว +2

    Really great videos!!
    As a newcomer this is helping me a lot.
    Thanks!

  • @tomasmunoz1641
    @tomasmunoz1641 ปีที่แล้ว +39

    Bro just wanted to thank you for such amazing content, the consistency with which you upload together with the widespan of python related content you cover is unparalleled hope the channel continues to grow

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

      +1

    • @edwardsnowden8749
      @edwardsnowden8749 11 หลายเดือนก่อน

      Legit I had discovered this channel when he'd just posted his videos on python, and i saw how structured and complete his content was, and I knew at that time this channel deserved more followers, but I had nothing to do with python at that point. 2 years later, Here I am, doing a 6 month internship on Python, and i come to youtube to learn about Threading in python, and I land on this video.

  • @moibe182
    @moibe182 20 วันที่ผ่านมา

    Nice and straight to the point!, thanks!!!

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

    Thank you, bro. Your lessons are very helpful and easy to understand.

  • @lanadelreyedits2234
    @lanadelreyedits2234 27 วันที่ผ่านมา

    That was awsome, thank you so much for sharing your knowledge.

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

    Another great vid. Very well explained.

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

    Well done. Easy to understand and follow.

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

    Great concise explanation. Thanks!

  • @Nik-rx9rj
    @Nik-rx9rj หลายเดือนก่อน

    This was incredibly easy to understand. Thank you!

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

    FINALLY someone who can explain this clearly!

  • @arhamsiddiqui2365
    @arhamsiddiqui2365 7 หลายเดือนก่อน

    It cleared all my doubts ! Thanks !

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

    You make great, very understandable tutorials

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

    Thank you so much for this... short and clear

  • @ramizballou5197
    @ramizballou5197 5 หลายเดือนก่อน

    Very good tutorial - thanks for sharing and being so resourceful 👍👍

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

    Thanks man, this was really helpful.

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

    Great job! Fastest 8 minutes ever for me!

  • @imrealgigachad
    @imrealgigachad ปีที่แล้ว +4

    Very nice video, keep going bro

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

    This is great. Thanks for sharing.

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

    Quick, Simple and Useful tutorial
    Many thanks ;)

  • @damianos.2954
    @damianos.2954 ปีที่แล้ว

    very nice explanation. Subscribed!!

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

    Ayy my man thankd very much for that tutorial i totally understand the concept 🙌

  • @its_me_to
    @its_me_to 3 หลายเดือนก่อน

    Thank you for fast and simpel tutorial

  • @nonebusinessaccount496
    @nonebusinessaccount496 3 หลายเดือนก่อน

    Thank you for the explanation. Very impressive.

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

    A bit of clarification. A tuple with a single value without the coma after it e.g. ("ABC",) will cast the value to a string. ("ABC") = "ABC". ("ABC",) = ("ABC").

  • @KuriSumireko
    @KuriSumireko 3 หลายเดือนก่อน

    Thanks doc, helped me with my homework

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

    Great Video!

  • @GuitarLucius
    @GuitarLucius 5 หลายเดือนก่อน

    very well done mate. thank you..

  • @patrickmaartense7772
    @patrickmaartense7772 5 หลายเดือนก่อน

    very clearly explained...

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

    after watching many videos on multithreading , this one takes the point home

  • @malathinaik1971
    @malathinaik1971 5 หลายเดือนก่อน

    thank you so much !!!

  • @user-ns4db4yk6c
    @user-ns4db4yk6c 24 วันที่ผ่านมา +1

    amazing!

  • @user-em2cl9qd9c
    @user-em2cl9qd9c 6 หลายเดือนก่อน

    thanks..."that daemon=True little snippet of info".....helped me save a problem in 4minutes ...regards and have a good time

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

    thanks, nice content

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

    Great video well explained

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

    Hi, thanks for the video. I think the not deamon thread doesn’t stop in your video because the function is set to while True instead of while Done :)

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

    let it be known that this man is a goddamn legend

  • @naderbazyari2
    @naderbazyari2 11 หลายเดือนก่อน

    Great video like everyone said. Ich bedanke mich. I just leave a comment for the algorithm to recommend it to more people

  • @greofficial980
    @greofficial980 7 หลายเดือนก่อน

    Great teacher

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

    You are amazing!!

  • @Luc1an_
    @Luc1an_ ปีที่แล้ว +16

    Could you please also explain multithreading vs multiprocessing in the next video??

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

      The way i understand it is that multiprocessing is just using more than 1 cpu core to do the task at hand. Multithreading would then be using a single core to do 2 or more operations "at once" by hopping back and forth between 2 or more tasks.
      Btw im fairly new to programming so i might be incorrect. If anyone can confirm please comment or something

    • @heco.
      @heco. ปีที่แล้ว

      ​​@@BAMBAMBAMBAMBAMvalyour're right

    • @TheEpicPineapple56
      @TheEpicPineapple56 10 หลายเดือนก่อน +10

      @@BAMBAMBAMBAMBAMval Hey, so this isn't quite true. Python can be quite a bit different from other languages and adhere to its own way of doing things sometimes, so as someone new to programming, you're probably getting a few misconceptions. Multiprocessing and multithreading are both ways of implementing "concurrency". "Concurrency" encompasses both real parallelism and the simulated "hopping back and forth" between different tasks. Multiprocessing differs from multithreading because it spawns an entire new child process through a process called "forking". You need to know what processes are to really get this, so essentially a process is like a miniature computer system; it has its own CPU registers, its own memory address space, its own PC counter, etc etc. It is like a little miniature box that was developed decades ago as a way to allow one computer to run multiple programs at the same time. A child process contains a copy of every variable, every object, etc in the parent process at the time that it was forked. These two processes now run at the same time. On a single-core machine, the CPU would be bouncing around doing tasks for both processes at the same time. On a multi-core machine, sometimes the two processes would literally, physically be running at the same time on different physical cores that the CPU has. In practice, this is called "multiplexing" and it is the job of the operating system and the CPU scheduling hardware to adequately schedule the hundreds of different processes that run on a computer. There are a few stages that a process can live in: "new", "ready", "running", "waiting", and "terminated" (this depends on your OS as well, I am talking about Unix operating systems mostly).
      Threads are a lighter-weight way of implementing concurrency. Threads do not have their own address space the same that processes do, and they do not make copies of any variables. Threads are essentially just there to execute instructions and operate on the same data that already exists in the main process. Because of that, it is very important to synchronize threads and make sure that when they are interacting with data, they avoid creating situations called race conditions. As a programmer, you need to implement/use things like locks, mutexes (mutual exclusions), and semaphores to make sure that data is accessed in the correct way. With all that being said, threads also give concurrency, which may be real parallelism or maybe "fake" parallelism achieved through time multiplexing. Threads live on different levels of the operating system too. Some are user threads, like the ones in Python. Others are kernel level threads, which have permission to interact directly with the hardware. And of course there are hardware threads, which are the 4 cores, 8 cores, 16 cores, etc that you have on your CPU. If your computer has 16 cores and is running more than 16 processes and threads, then it is 100% doing some level of time multiplexing. It is impossible to not do that. But there are always at least 16 processes/threads that are truly executing in parallel, unless you write some code that stalls them.
      I know that was a lot, and there is lot of nuance that I missed so for anyone that reads who knows better I apologize lol
      Just wanted to give a quick rundown of the differences, similarities, and how you really need to get to the hardware and operating system level of things to understand what is going on. Python abstracts all of that away which makes it difficult to see.

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

      @@TheEpicPineapple56 hey thanks for taking the time to explain all that

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

    beautifully done.

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

    Really nice👍

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

    Very useful for video game development.

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

    Great explantion

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

    thank you very much

  • @techwizSon
    @techwizSon 9 หลายเดือนก่อน

    bro really help me understand thread

  • @AliHamza-en8cn
    @AliHamza-en8cn ปีที่แล้ว

    Great video. Can you make video about create an installer of python scripts like installing normal software and show on control panel?

  • @antonmazur6301
    @antonmazur6301 9 หลายเดือนก่อน

    You know it's a good video if a dummy like me understood everything. Thank you very much!

  • @thekreb
    @thekreb 6 หลายเดือนก่อน

    OK... Finally a simple straightforward quick explanation of Python😅 threading

  • @user-yq8rk9sk5e
    @user-yq8rk9sk5e ปีที่แล้ว

    Thank you!

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

    Hi, i have a question? what if i want to add like , when press enter the value of counter value change to less one, and after this it works as from this value. please reply

  • @md.towfiqurrahman3316
    @md.towfiqurrahman3316 7 หลายเดือนก่อน

    nice explanation

  • @user-uc8yc4vv1g
    @user-uc8yc4vv1g 11 หลายเดือนก่อน

    keep it going bro

  • @acromatic0189
    @acromatic0189 9 หลายเดือนก่อน

    thank you

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

    Thanks 👍

  • @vaulttectradingco8438
    @vaulttectradingco8438 ปีที่แล้ว +17

    Threading is so much nerfed in Python that async often beat it

    • @-_Nuke_-
      @-_Nuke_- 5 หลายเดือนก่อน +1

      Is there a language that's like python (as similar as possible) but also supports true multi threading?

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

      @@-_Nuke_-you could look into Scala

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

    In the threading examples, what is magic about the variable 'done'? Boolean references to this variable in the def were replaced with the constant True. How does the def know that 'done' has changed from False to True?

  • @younesdeveloper
    @younesdeveloper 3 หลายเดือนก่อน

    amazing

  • @wiseworks6880
    @wiseworks6880 6 หลายเดือนก่อน

    Good high density tutorial.. I could have used some more explanation of join().

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

    thanks for the tutorial, btw dude you really look like the "Nacho" from better call saul 😆

  • @davidgood840
    @davidgood840 10 หลายเดือนก่อน

    Does this method still work if one thread makes calls to blocking functions inside a foreign dll ?

  • @-_Nuke_-
    @-_Nuke_- 5 หลายเดือนก่อน

    Does java support true multi threading? Meaning assigning different code to run in true parallel in separate threads in my CPU?

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

    Hi, anyone can answer me about args in a thread, isn't a list by default ?
    I always pass a list as args, if you only have one, you only pass one, why a tuple exactly ?

  • @mmmm-uc8ed
    @mmmm-uc8ed ปีที่แล้ว

    Top g of programming

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

    Can you explain asyncio and why everyone uses it instead of threading nowadays

  • @gecko_ecco2017
    @gecko_ecco2017 6 หลายเดือนก่อน

    Can someone explain why the "args" takes a tuple if you use () or a list [] but not a single argument? and what argument takes "kwargs"?

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

    I love learning python from Vaas

  • @yosef_ii
    @yosef_ii 6 หลายเดือนก่อน

    YOU HELPED ME SO MUCH THANK YOUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU

  • @PCs454
    @PCs454 4 หลายเดือนก่อน

    When i make a thread, i get a RuntimeError: There is no current event loop in thread 'Thread-1
    i copied some code that uses something called *asyncio* ? but i do not understand what this means or does exactly :( could someone please explain this breifly. or are there other parts to this video? thanks 🙏🙏

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

    i’ve heard that python 3.14 will be up to 5 times faster. do you think it is possible, that python will get real multithreading?

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

    thanks

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

    great video! i joined DC, but cannot verify with my phone, im afraid it could be leaked, what should i do?

  • @ed223-p5g
    @ed223-p5g ปีที่แล้ว

    Next video about multiprocessing pls

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

    can you make a video on threadpool executor please

  • @AmodeusR
    @AmodeusR 10 หลายเดือนก่อน

    I didn't get how the code stopped running when you pressed enter. Why only when you pressed enter it went after the print? For what I know the code should be executed right after the print, making so the counter wouldn't even happen since done would be set to True before it could start.

  • @Reall
    @Reall 3 หลายเดือนก่อน

    My question is if the thread hasn't finished can you still access it if you exited after

  • @evanhearne-witstudentappli1182
    @evanhearne-witstudentappli1182 11 หลายเดือนก่อน

    I must say, you charge very reasonably for your paperback books. I think that's great.

  • @qbicc6381
    @qbicc6381 22 วันที่ผ่านมา

    What exactly makes it only recognize "Enter" as a correct input for triggering done?

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

    how do you embed thread sin classes to run functions?

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

      hyperpush the thread

  • @fadhlurrohmanfaqih480
    @fadhlurrohmanfaqih480 3 หลายเดือนก่อน

    Hi there, I face a problem that I can't solve. I'm setting my code to daemon thread (while True, daemon=True, and also done=True), but after I press enter the code still running, I need to set "while not done" to get a proper result (but the code still printing another 1 number after I press the enter). Can you please tell me what happened sir? Thankyou

    • @fadhlurrohmanfaqih480
      @fadhlurrohmanfaqih480 3 หลายเดือนก่อน

      oh I'm using jupyter notebook to run the code

  • @alvaronorambuena2254
    @alvaronorambuena2254 9 หลายเดือนก่อน

    genio

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

    I learn something :)

  • @Lorryduckie2
    @Lorryduckie2 5 หลายเดือนก่อน

    this was not cristal clear to me but probabely need to get deeper in other concepts before jumping to threads. nevertheless quality content thanks

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

    how to combine threading with schedule?

  • @LucasDavid-ix3tw
    @LucasDavid-ix3tw 5 หลายเดือนก่อน

    Im copying the exactly same code from the video but my input It is not stoping the loop. Why? :/

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

    How to get real multi thr?

  • @emrecagr6314
    @emrecagr6314 7 หลายเดือนก่อน

    you looks like Michael Mando so much man :) check it

  • @PokettoMusic
    @PokettoMusic 5 หลายเดือนก่อน

    based

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

    I want to be freinds with this guy talk python I need more info like I see you cab create anything you want

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

    Can your help me?,how make file manager in dearpygui?

  • @Mr.Guilherm
    @Mr.Guilherm 7 หลายเดือนก่อน

    Devil 😈😈😈😈

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

    gg