Deutsch English Français Italiano |
<mailman.8.1727297070.2990.python-list@python.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Cameron Simpson <cs@cskk.id.au> Newsgroups: comp.lang.python Subject: Re: How to stop a specific thread in Python 2.7? Date: Thu, 26 Sep 2024 06:44:09 +1000 Lines: 23 Message-ID: <mailman.8.1727297070.2990.python-list@python.org> References: <CAGJtH9RBmcofpg5ifiXZm4z8XRBQkGVzDSduR7=9QH75-Ubpgw@mail.gmail.com> <ZvR2GbgY9Xs33hNm@cskk.homeip.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: news.uni-berlin.de aQvznE4HOXkI2tSXdtA2VghCbmGHxzlghbUuF1d0gsZQ== Cancel-Lock: sha1:BVZL0V+Rp4MfmXB9lfyEA7nROYQ= sha256:q6ZsNMusNciWnDOyF8vfZkW/0u/QX2Zjl8JDl2wCv4s= Return-Path: <cameron@cskk.id.au> X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org Authentication-Results: mail.python.org; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'thread': 0.05; 'set.': 0.09; 'cheers,': 0.11; 'subject:Python': 0.12; 'cameron': 0.16; 'from:addr:cs': 0.16; 'from:addr:cskk.id.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:13.237': 0.16; 'received:13.237.201': 0.16; 'received:13.237.201.189': 0.16; 'received:cskk.id.au': 0.16; 'received:id.au': 0.16; 'received:mail.cskk.id.au': 0.16; 'simpson': 0.16; 'skip:> 10': 0.16; 'skip:> 20': 0.16; 'subject:2.7': 0.16; 'subject:stop': 0.16; 'subject:thread': 0.16; 'wrote:': 0.16; 'instead': 0.17; 'to:addr:python-list': 0.20; 'to:no real name:2**1': 0.22; 'subject:How': 0.23; 'run': 0.23; 'header:User-Agent:1': 0.30; 'sfxlen:2': 0.31; "doesn't": 0.32; 'but': 0.32; 'there': 0.33; 'header:In-Reply-To:1': 0.34; 'running': 0.34; 'received:au': 0.35; 'single': 0.39; 'want': 0.40; 'event': 0.40; 'becomes': 0.64; 'received:13': 0.64; 'well': 0.65; 'skip:t 20': 0.66; 'received:userid': 0.66; 'following:': 0.69; 'id)': 0.84; 'subject:specific': 0.84 Mail-Followup-To: Tutor@python.org, python-list@python.org Content-Disposition: inline In-Reply-To: <CAGJtH9RBmcofpg5ifiXZm4z8XRBQkGVzDSduR7=9QH75-Ubpgw@mail.gmail.com> User-Agent: Mutt/2.2.13 (2024-03-09) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.39 Precedence: list List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> List-Archive: <https://mail.python.org/pipermail/python-list/> List-Post: <mailto:python-list@python.org> List-Help: <mailto:python-list-request@python.org?subject=help> List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> X-Mailman-Original-Message-ID: <ZvR2GbgY9Xs33hNm@cskk.homeip.net> X-Mailman-Original-References: <CAGJtH9RBmcofpg5ifiXZm4z8XRBQkGVzDSduR7=9QH75-Ubpgw@mail.gmail.com> Bytes: 3864 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>