Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #196760 > unrolled thread
| Started by | Left Right <olegsivokon@gmail.com> |
|---|---|
| First post | 2024-09-25 22:14 +0200 |
| Last post | 2024-09-25 22:14 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How to stop a specific thread in Python 2.7? Left Right <olegsivokon@gmail.com> - 2024-09-25 22:14 +0200
| From | Left Right <olegsivokon@gmail.com> |
|---|---|
| Date | 2024-09-25 22:14 +0200 |
| Subject | Re: How to stop a specific thread in Python 2.7? |
| Message-ID | <mailman.12.1727363790.2990.python-list@python.org> |
That's one of the "disadvantages" of threads: you cannot safely stop a thread. Of course you could try, but that's never a good idea. The reason for this is that threads share memory. They might be holding locks that, if killed, will never be unlocked. They might (partially) modify the shared state observed by other threads in such a way that it becomes unusable to other threads. So... if you want to kill a thread, I'm sorry to say this: you will have to bring down the whole process, there's really no other way, and that's not Python-specific, this is just the design of threads. On Wed, Sep 25, 2024 at 7:26 PM marc nicole via Python-list <python-list@python.org> 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? > > Thanks! > -- > https://mail.python.org/mailman/listinfo/python-list
Back to top | Article view | comp.lang.python
csiph-web