Python Multithreading Tutorial #1 - What is a Thread?

Поделиться
HTML-код
  • Опубликовано: 7 сен 2024
  • This python multithreading tutorial talks about what a thread is and how it compares to a process. Multithreading is a commonly used strategy to improve the efficiency of code. When multiple threads are running if the current thread delays or is waiting for something then the next thread will start executing.
    Source-Code: Coming soon...
    Playlist: • Python Multithreading ...
    ◾◾◾◾◾
    💻 Enroll in The Fundamentals of Programming w/ Python
    tech-with-tim.....
    📸 Instagram: / tech_with_tim
    🌎 Website techwithtim.net
    📱 Twitter: / techwithtimm
    ⭐ Discord: / discord
    📝 LinkedIn: / tim-rusci. .
    📂 GitHub: github.com/tec...
    🔊 Podcast: anchor.fm/tech...
    💵 One-Time Donations: www.paypal.com....
    💰 Patreon: / techwithtim
    ◾◾◾◾◾◾
    ⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡
    Tags:
    - Tech With Tim
    - Multithreading in python
    - Python multithreading tutorial
    - Python Tutorials

Комментарии • 33

  • @elishashmalo3731
    @elishashmalo3731 5 лет назад +20

    PLEASE DO MORE PYTHON PROBLEMS AND SOLUTIONS!!
    Like one a week?

    • @TechWithTim
      @TechWithTim  5 лет назад +1

      Possibly!

    • @willgiovanni2041
      @willgiovanni2041 3 года назад

      Pro trick: you can watch series at flixzone. Me and my gf have been using them for watching lots of of movies lately.

  • @FeedFall8
    @FeedFall8 5 лет назад +1

    this video helped me reduce lag in my applications that have over 250,000 objects

  • @anonjr7585
    @anonjr7585 5 лет назад +2

    nice video man, i was unable to understand at beginning when i looked at the code, but then i understood evrything after your illustrations.

  • @FeedFall8
    @FeedFall8 5 лет назад +7

    also Great video As usual Tim :)

  • @baruchba7503
    @baruchba7503 5 лет назад +3

    If it's possible to show msec in the clock time this may be a better demonstration to show how the threads wait and start.

  • @upasanadhameliya9911
    @upasanadhameliya9911 3 года назад

    Awesome tutorial dude! You're really talented :))

  • @DanielWeikert
    @DanielWeikert 5 лет назад +6

    Is there any priority? Lets say thread 1 sleeps so thread 2 starts and takes 5 minutes without a break to finish. thread 1 (half executed) would then have to wait 5 minutes until it resumes and finishes then?

    • @TechWithTim
      @TechWithTim  5 лет назад +1

      good question, yes you would have to wait. There is ways around this however...

    • @DanielWeikert
      @DanielWeikert 5 лет назад

      @@TechWithTim thanks Tim

    • @chujuntang3517
      @chujuntang3517 5 лет назад

      I think thread priority is not controllable in Python due to unawareness of GIL to switch thread.

  • @devpatel6319
    @devpatel6319 4 года назад

    Perfect explanation .. keep it up 👻👍👍👌

  • @muizzy
    @muizzy 5 лет назад +2

    "Multithreading" is a very big word when it comes to plain python. You won't be getting any significant performance gain from doing it.
    If you want to achieve actual multi-threading in python, the best way I know of is to use Konrad Hinsen's modified Python interpreter together with his Bulk Synchronous Parallel (BSP) module included in his scientific python package: bitbucket.org/khinsen/scientificpython
    The problem is that Python's GIL will protest against any form of parallelisation. I tried to build a package that could deliver a Python based BSP package, but was unable to get the GIL to play nice in any generalised case. Hence, the project is currently on the backburner.

    • @TechWithTim
      @TechWithTim  5 лет назад +1

      Yes you’re correct, to create parallelism you need to use multiprocessing! Multi threading is great for networking applications however because when waiting for tasks to be completed then you can have other threads running in the background. I will be doing a multiprocessing tutorial after this one !

    • @muizzy
      @muizzy 5 лет назад

      @@TechWithTim ... wait ...
      You know of a way to get around the GIL??
      Do you have any links to resources?

    • @TechWithTim
      @TechWithTim  5 лет назад +1

      @@muizzy It's not necessarily getting around GIL... It's using multiple GIL, you can create more than one process of your program and have them run in parallel on separate cores or CPU's. The issue here is its much more difficult to share information between processes because they have their own memory location. Just try looking up the processing module in python, not sure if it will fix your issue but have a look.

    • @muizzy
      @muizzy 5 лет назад +4

      @@TechWithTim Dude, this actually ended up fixing all my problems. Two days of frantic coding later, I've got a working (and beautiful) proof of concept!

  • @sainco3036
    @sainco3036 5 лет назад +1

    thanks.

  • @Hamheadon
    @Hamheadon 2 года назад +1

    My main wonder is what happens if you set two threads to delay for the same intervals of time

  • @arshia.sasson
    @arshia.sasson 4 года назад +1

    I am looking into making a device manager that would interact with several comports (at least 2-3, but could be as many as 6) that would read logs/write commands. What would be the most efficient implementation? Running each port in its own thread? Perhaps dedicate a core to running all of the serial port threads? How would I share the logs read into each serial port with the main thread running the computation/testing?

  • @hammzahammza7914
    @hammzahammza7914 5 лет назад

    thank you very mush

  • @ashishsrivastava123
    @ashishsrivastava123 4 года назад

    Please make video on vscode..its very good.. but lot of issue we face while running e.g. extension do not load, update json files etc ( Python ML developer )

  • @aryanbhatia6992
    @aryanbhatia6992 5 лет назад +1

    When are deep learning tutorials coming ??

  • @awwwwhhhyeahhhh
    @awwwwhhhyeahhhh 5 лет назад +1

    I'm just getting into threading for my kivy app. The reason being is that I have an nslookup function bound to a kivy button and on the button press a progress spinner should appear while the nslookup is running. However when I press the button the app freezes (presumably because the function is an nslookup and doesn't actually interact with the GUI). So my thinking is that I run the function and the progress spinner animation on different threads so the spinner doesn't have to wait for the nslookup to complete. Am I thinking along the right lines here? Will threading help me to achieve this or should I be looking into something else?

  • @maulikmadhavi
    @maulikmadhavi 3 года назад

    why different number of empty spaces? Can anyone explain? Thanks

  • @manishkumar-bh6cc
    @manishkumar-bh6cc 5 лет назад

    Bro can you upload a tutorial in webscraping in python

  • @kitgary
    @kitgary 4 года назад

    Any thought about the gevent? Is it good?

  • @munivoltarc
    @munivoltarc 8 месяцев назад

    where did you learn this, can u share the resource, if it is a pdf?

  • @chujuntang3517
    @chujuntang3517 5 лет назад +1

    I think it's Python which cannot run two threads at the same time due to GIL.

  • @FeedFall8
    @FeedFall8 5 лет назад

    OMG PYGAMES WEBSITE IS DOWN WHATS HAPPENING?!?!?!?!?