Threading in Python - Advanced Python 16 - Programming Tutorial

preview_player
Показать описание
Threading in Python - Advanced Python 16 - Programming Tutorial

In this Python Advanced Tutorial, I will go into more detail about the threading module in Python. This video will cover:

- How to share data between threads
- Hot to use Locks to prevent race conditions
- What is a daemon thread
- How to use a Queue for thread safe data exchanges

~~~~~~~~~~~~~~ GREAT PLUGINS FOR YOUR CODE EDITOR ~~~~~~~~~~~~~~

📚 Get my FREE NumPy Handbook:

📓 Notebooks available on Patreon:

A written Tutorial can be found here:

You can find me here:

#Python

----------------------------------------------------------------------------------------------------------
* This is a sponsored link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏
Рекомендации по теме
Комментарии
Автор

I hear "daemon thread" as "demon threat", I played too many videogames...
To quote: "A demon threat is a background threat that will die when the main threat dies"

vladimirtchuiev
Автор

Subscribing. Python Engineer, your tutorials are filled with well delivered content. Thank you for your time and effort😲!!!

kevinjones
Автор

I did think Queue was already thread safe, that it won't require a lock. Anyway, thank you by the great content.

alvfig
Автор

Amazing video! Thank you so much for making this great explanation!

squeakycamp
Автор

I don't get your example for `with lock: ` usage. With GIL enabled, how can one print() call be executed inside another one? ~Or, printing to Console is IO-bound operation?~
EDIT: OK, read an article and understood: the main text and '\r\n' can be interjected with more text because how print() itself works.

hackdesigner
Автор

Thanks for the video, nicely explained

sigmasix
Автор

Love your content, thank you.

future topic suggestion : pytest integration test 🙏🏼

vijaybabaria
Автор

Superb video on multithreading topic Explanation is absolutely crystal clear... Thanks for uploading video

sharifmansuri
Автор

i have never encountered a race condition, but if i do, the `Lock` will be ideal...

darrenlefcoe
Автор

If we lock the thread, won’t that defeat the purpose of threading(that is to switch to another task while waiting for IO to respond?)

Are there other ways to communicate, while ensuring that we can still switch between tasks?

liushaomin
Автор

Thank you guy, very helpfull and very good explanation ;D

kosonko
Автор

For some reason the final code doesn't work for me in vscode and doesn't even return an error, while on pycharm it works just fine.
EDIT: it started working but only if I use the debug mode

Loug
Автор

Thank you very much for detailed & clear explanation. Rare type of great content!

benyaminyakobi
Автор

hi, i have a doubt i would appreciate it if you could ans.
if i have a flask service in which a function is there which gets executed

app.route(/, ['POST'])
def sum():
addition, status = addition(x, y)
q1 - if some one wants send multiple request to my api how do i make it concurrent as well as thread safe, ???
q2 -> and if different threads are getting created then should i have to make variable inside the addition method thread safe or they just local variable and won't be affected.
q3-> add function return two values will they be affected by different threads. and how do i get return values after writing threading code.
should i do like
addition, status = thread.start()
????

abhisekhagarwala
Автор

I have listened to all of this series of videos and found them exceptionally well explained - up until this one. Q.join came from nowhere and was not explained and the whole rather complicated interaction of the various parts was unclear. Sorry but it is better to be honest. Alan

alanjohnstone
Автор

Hello Patrick, please explain this to me again:
In your video at 21:51
1. why does the main thread die if there is an infinite loop?, does q.join() somehow stops it ?
I understand that after task_done() the thread should still be 'stuck' in the loop even though q.join() 'gathers' all the final results but...
2. ...how does it stop the loop? and
3. why would we use an infinite loop in the first place?
I am sorry if my questions seem very obvious, thank you in advanced and thank you for this material.

kaxurxsurt
Автор

Which IDE / Text editor you are using?

intisarmuhtadee
Автор

is anyone else hearing 'thread' as 'threat' ?

PRATIKADARSH
Автор

Everyone is İndian in here ı think so...(but ı am not ındıan)

spy