Locking & Synchronizing Threads in Python

Поделиться
HTML-код
  • Опубликовано: 14 окт 2024
  • Today we learn how to synchronize threads by locking shared resources in Python.
    ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
    📚 Programming Books & Merch 📚
    🐍 The Python Bible Book: www.neuralnine...
    💻 The Algorithm Bible Book: www.neuralnine...
    👕 Programming Merch: www.neuralnine...
    🌐 Social Media & Contact 🌐
    📱 Website: www.neuralnine...
    📷 Instagram: / neuralnine
    🐦 Twitter: / neuralnine
    🤵 LinkedIn: / neuralnine
    📁 GitHub: github.com/Neu...
    🎙 Discord: / discord
    🎵 Outro Music From: www.bensound.com/

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

  • @scottlee38
    @scottlee38 2 года назад +8

    Yes. Thanks!
    We need more "Threading" videos!!

  • @ΑρηςΕμπαντα
    @ΑρηςΕμπαντα Год назад +2

    I didnt get it... First we had synchronous code. Then we deployed threads to do things concurrently (awesome for I/O bound tasks), and then with locking we made the code synchronous again? For what you want to perform, either multiprocessing can help you, or to switch to other programming language like C# or Java that actually runs threads in parallel.... Why doesn't nobody else in the comment section address that stuff?

    • @tomekk.1889
      @tomekk.1889 Год назад +1

      I don't understand what you mean. Locking is used so there's no race conditions between the threads. His example wasn't good though. He should have explained it using producers and consumers

    • @monishsudhagar
      @monishsudhagar Год назад

      Yeah, just bad use case. When you work with produces and consumers or any multithreaded application with a shared state, then locking starts to make sense

    • @hams6468
      @hams6468 10 месяцев назад

      Locking is useful if for example - you have to make an API request to pull some data & then cache it. You simply lock so that a thread can go and pull data from an api & cache it, then all other threads can use that cache.

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

    If you acquire lock using with statement. It will make sure lock will always be released.

  • @BrianStDenis-pj1tq
    @BrianStDenis-pj1tq 2 года назад +1

    You pretty much said Python doesn't have multi-threading, presumably due to the impact of the GIL. I'd say that Python does have multi-threading, and the GIL. Which means that for CPU bound threads, its very similar to having a single CPU. But, for I/O threads, it works great.

    • @ΑρηςΕμπαντα
      @ΑρηςΕμπαντα Год назад

      You just can use multiprocessing if you have a 4 core CPU to do 4 CPU bound tasks in paralel... But true for I/O tasks python threads are great

  • @scottlee38
    @scottlee38 2 года назад

    I ran into this same issue with thread locks. Wish there was a way to get around it so that I could keep threads for certain loops "always running".

  • @DG-mo1nw
    @DG-mo1nw 2 года назад

    Thanks for the videos been learning a lot. Is there any way you could do a video using tradingview webhooks for indicators for a trading bot using python?

  • @iniyan19
    @iniyan19 2 года назад

    thanks !!! i was searching for this!!!

  • @chriskeo198
    @chriskeo198 2 года назад

    best video on threading!

  • @ilanbar1970
    @ilanbar1970 2 года назад

    Well explained. Thanks!

  • @good-oe2cz
    @good-oe2cz 8 месяцев назад

    it was a bit rough explanations. with better example and concept of context change, it would be a better explanation. thank you for your video.

  • @peperomero4603
    @peperomero4603 5 месяцев назад

    bravo!

  • @pawelek1481
    @pawelek1481 2 года назад

    Lets make your connection pool