Python Threading Examples - Issues and Caveats

preview_player
Показать описание
In this video I show a couple of examples implementing some Python multithreading techniques, such as creating, starting and joining threads, daemon threads, locks, and threadsafe queues (this is not really a tutorial on threading - that would be an entire course, but more of a demo of what can go wrong and a common misconception).
My main aim in this video is to show that multithreading (in Python) does **nothing** to improve performance in CPU bound workloads, and hopefully convince you that writing multithreaded code is not something you should just do casually as it is very easy to introduce (often invisible) bugs and is not some kind of performance improving magic bullet.

#mathbyteacademy #python

Code for this Video
================

My Python Courses
=================

- Python 3 Fundamentals (introduction to Python)

- Python 3 Deep Dive (Part 1 - Functional)

- Python 3 Deep Dive (Part 2 - Iteration, Generators)

- Python 3 Deep Dive (Part 3 - Hash Maps)

- Python 3 Deep Dive (Part 4 - OOP)
Рекомендации по теме
Комментарии
Автор

I seriously love this man and how generous he is with his knowledge.

Thanks Fred for your work

MohamedAhmed-rfbk
Автор

Fred’s wisdom and knowledge on Python surpasses an advanced deep learning AI trained for billions of hours on how to use python most effectively.

ceebz
Автор

The best Python-related content in the web.
Cant wait for async and multiprocessing examples!

cudanakiju
Автор

This is really a great presentation with clear logic and well-organised examples. Thanks!

chrisyoung
Автор

The examples were perfect for explaining the usage of multithreading and their limitations. Fantastic!

iChrisBirch
Автор

I think that many of us thinks that, in some way, multi threading will speed up the app. But as you explain here, it is not quite simple. Anyway, thanks for sharing!!

valentinplechuc
Автор

Thanks fred. I was waiting for this course

selvamm
Автор

I just finished the video. Thank you, thank you.
Went to your udemy courses too. Thank you

Now, I don't like multithreading that much :)

abdellahiaioun
Автор

Thanks Fred as always best courses / explained ! I am waiting for a design pattern course !!!

bennykopilov
Автор

Dear Sir. You are awesome. I was terrified of coding. My friend suggested your Udemy course. I am going through it. It made coding easy for me. Sir, please make a course on Data Science and Machine Learning.

ApneDharamSeJudo
Автор

Good explanations (the first example seems a bit contrived, as you mentioned, but ok). But, the explanation you provided at 48:12 on why locking is not necessary is a bit misleading in my opinion.

The main reason why locking isn't required is because append on a list is atomic. (More can be read at Python's docs FAQ under What kinds of global value mutation are thread-safe?)

fkdosilovic
Автор

Does this included in any of the part in your's udemy course? Please let me know sir, i am looking to buy your all part it would be better if i find one spot source which covers all python topics

sarthak-salunke
Автор

You are the best. Thank you for this video. Can you, please, make an some kind of deep understanding for the Async? I've bought all your courses in udemy and still in the process of working with them, but in topics I haven't seen such topic. So it would be great if you will make video of additional course for the async programming, understanding of it and best practises.

redDuck
Автор

Great video! That was a lot of great information. I wasn't aware of the daemon thread type and that is pretty cool. I am a network engineer and I find myself using threading a lot for speeding up my code that sends commands to many different network devices over ssh. I use concurrent.futures ThreadPoolExecutor with the map method and I find it to be very helpful. I use a thread safe logger in the code and return the result I need from the function sent to threads. The function used in threads doesn't use any global variables and doesn't modify any of the arguments passed to it. Then outside of the threads I put the results together into a larger data structure. To test some of this I would keep a threaded version and non-threaded version to compare the results to make sure they were always the same.

kosmonautofficial
Автор

Personally, I always thought multi-threading is the way to go to make a program faster but I also looked into approaches like asyncio, concurrent.futures. But they all are fuzzy topics to me.

reneeliu