How Do You Kill a Python Thread?

preview_player
Показать описание
Two ways to kill a Python thread!
Рекомендации по теме
Комментарии
Автор

This is really nice trick. Never heard of events from Threading library but yeah this makes handling threads at app exit much simpler and cleaner.

rohitbhanot
Автор

I would like see more topics about Multithreaded and AsyncIO. Thanks!

oleksisfraga
Автор

I give like even before the video starts. You're the best! Thank you.

Felipe-
Автор

Thanks Miguel for sharing your knowledge! It means a lot! 👌

aminghanooni
Автор

after 2 hours of pain I see you video and it works instantly thx you fella you carried this !

Globulov
Автор

Great video.

I have a python webapp where users send a request which needs to do some background work, I launch a new thread for each request and return a request id to user immediately. Thread does it's task for about 5 minutes, and adds result to db.

In some conditions I receive a stop request with request id for a previous request, how should I stop the thread I had started for that request id ? Is Is it a good idea to maintain a dict of request_id|thread on request and later use dict to stop that particular thread ? I don’t have any for loops in thread

soneshdabhi
Автор

Good explanation what about same scenario but more than one threads. Everyone of em is going to print iteration complete statement before exiting?

xmkay
Автор

What if i have no access to the code executed on the thread?
In my case, I am given a piece of code to run on my thread, there is no while loop where i can check periodically for stop flags, it's just one function reference call.
How would i tell the thread to stop executing then?
Basically you can't touch your "bg_thread()" method.
Are there no outside controls available to stop the thread execution?

Sithlord
Автор

Nice tutorial Sir. I have question. Is it possible to stop only the specific thread and not to stop the main thread? Eg. i have main thread running, and have 4 threads running on that function. I want to stop the 3rd thread alone without affecting the rest of the threads. Is possible?

rswpmkp
Автор

Appreciate the effort!

I will actually use this in a few hours!

scottlee
Автор

found this immensely useful. how can i do that for certain condition when using multithreads

yashgusain
Автор

Great content. Do you know if signals are also supported on Windows?

tekknokrat
Автор

man thank you so much this helped me a lot

unknownblueblue
Автор

Amazing, please keep making these videos ❤️

vaibhavkumarchaudhary
Автор

what if the function runs another unknown function that has a loop in It? I've been trying to figure It out how to handle this without knowing what the inner function looks like, but still no luck. My best bet so far is to use multiprocess, but that seems overkill

thales-maciel
Автор

Can I do the same using multiprocessing?

grothaal
Автор

What if I have a GUI where I want to have a Stop button to stop the thread? What do I write in the button's function to send the signal?

seyproductions
Автор

But what happens if I force close python while threads are running? What if a thread gets stuck in an infinite loop hypothetically? I have threads marked as daemon but I can't keyboard interrupt them.

michaeletzkorn
Автор

Interesting and nice video, congratulations !! Do you know how to kill a thread (useless) from the program in order to free the resources ?
I have not found information for that.

danielrabolon
Автор

But this exits the entire script, but i want to keep the script running and only end a specific thread.

holycow