Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #196753
| From | marc nicole <mk1853387@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: How to stop a specific thread in Python 2.7? |
| Date | 2024-09-25 22:56 +0200 |
| Message-ID | <mailman.9.1727297834.2990.python-list@python.org> (permalink) |
| References | <CAGJtH9RBmcofpg5ifiXZm4z8XRBQkGVzDSduR7=9QH75-Ubpgw@mail.gmail.com> <ZvR2GbgY9Xs33hNm@cskk.homeip.net> <CAGJtH9QwwYDRcqkM7Vtgy_ZraOZbrCcsyGODveNPFtpT7+L_6g@mail.gmail.com> |
How to create a per-thread event in Python 2.7? On Wed, 25 Sept 2024, 22:47 Cameron Simpson via Python-list, < python-list@python.org> wrote: > 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> > -- > https://mail.python.org/mailman/listinfo/python-list >
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How to stop a specific thread in Python 2.7? marc nicole <mk1853387@gmail.com> - 2024-09-25 22:56 +0200
csiph-web