Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #196752 > unrolled thread
| Started by | Cameron Simpson <cs@cskk.id.au> |
|---|---|
| First post | 2024-09-26 06:44 +1000 |
| Last post | 2024-09-26 06:44 +1000 |
| 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? Cameron Simpson <cs@cskk.id.au> - 2024-09-26 06:44 +1000
| From | Cameron Simpson <cs@cskk.id.au> |
|---|---|
| Date | 2024-09-26 06:44 +1000 |
| Subject | Re: How to stop a specific thread in Python 2.7? |
| Message-ID | <mailman.8.1727297070.2990.python-list@python.org> |
On 25Sep2024 19:24, marc nicole <mk1853387@gmail.com> wrote: >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? No, `set()` doesn't kill a thread at all. It sets the `Event`, and each thread must be checking that event regularly, and quitting if it becomes set. You just need a per-thred vent instead of a single Event for all the threads. Cheers, Cameron Simpson <cs@cskk.id.au>
Back to top | Article view | comp.lang.python
csiph-web