Re: How to stop a specific thread in Python 2.7?
Mats Wichmann <[email protected]> Wed, 25 Sep 2024 12:25:36 -0600
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Message-ID | <[email protected]> |
On 9/25/24 11:24, marc nicole via Tutor wrote: > Hello guys, > > I want to know how to kill a specific running thread (say by its id) > > for now I run and kill a thread like the following: > # start thread > thread1 = threading.Thread(target= self.some_func(), args=( ...,), ) > thread1.start() > # kill the thread > event_thread1 = threading.Event() > event_thread1.set() > > I know that set() will kill all running threads, but if there was thread2 > as well and I want to kill only thread1? There's no official way - as usual we'll come back with a question (well, I will): Why Would You Want To Do That? Threads often hold critical-section locks and other important things and killing such a thread will put you in an undefined, possibly unstable state. That may not be your case... it would be useful if you described a use case that causes you to want to kill an individual thread. Or are you just curious? _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor