Deutsch English Français Italiano |
<mailman.12.1727363790.2990.python-list@python.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!fu-berlin.de!uni-berlin.de!not-for-mail From: Left Right <olegsivokon@gmail.com> Newsgroups: comp.lang.python Subject: Re: How to stop a specific thread in Python 2.7? Date: Wed, 25 Sep 2024 22:14:43 +0200 Lines: 33 Message-ID: <mailman.12.1727363790.2990.python-list@python.org> References: <CAGJtH9RBmcofpg5ifiXZm4z8XRBQkGVzDSduR7=9QH75-Ubpgw@mail.gmail.com> <CAJQBtgmtB-Qxv2t+w41nkH6vgTTj9_JV7UEUuQS3hZUc6PBe5A@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de ex8GxqJQDd3AYSPa39tIAQ4G4O808n+CWVqlkWBaCgwQ== Cancel-Lock: sha1:kRY69YbJ4xRfO6toMQDhIB+xggc= sha256:OyftRUtlrdgcwH3igp33U32ZUcregEagDxlqIZ3WPdc= Return-Path: <olegsivokon@gmail.com> X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org Authentication-Results: mail.python.org; dkim=pass reason="2048-bit key; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=GrTmjZsn; dkim-adsp=pass; dkim-atps=neutral X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'this:': 0.03; 'thread': 0.05; 'cc:addr:python-list': 0.09; 'guys,': 0.09; 'memory.': 0.09; 'threads': 0.09; 'subject:Python': 0.12; 'url:mailman': 0.15; '2024': 0.16; 'idea.': 0.16; 'locks': 0.16; 'subject:2.7': 0.16; 'subject:stop': 0.16; 'subject:thread': 0.16; 'thread.': 0.16; 'wrote:': 0.16; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.23; 'subject:How': 0.23; 'run': 0.23; 'thanks!': 0.24; 'url- ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'cannot': 0.25; 'url-ip:188.166/16': 0.25; 'whole': 0.30; 'modify': 0.31; 'url-ip:188/8': 0.31; 'python- list': 0.32; 'sep': 0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32; "i'm": 0.33; 'there': 0.33; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34; 'running': 0.34; 'from:addr:gmail.com': 0.35; 'really': 0.37; 'way': 0.38; 'could': 0.38; 'shared': 0.39; 'wed,': 0.39; 'want': 0.40; 'sorry': 0.60; "there's": 0.61; '25,': 0.62; 'share': 0.63; 'down': 0.64; 'becomes': 0.64; 'well': 0.65; 'skip:t 20': 0.66; 'that,': 0.67; 'following:': 0.69; 'process,': 0.75; 'id)': 0.84; 'subject:specific': 0.84; 'safely': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727295295; x=1727900095; darn=python.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lqq1cNuC3bD2BpGXEYm7Tldi0hu4cGeS1oyzU9ngKpU=; b=GrTmjZsneyUFc3701hAh5d9jvhDZq02M3nCWb0sT7OYdLg6nte7iWvgMtFySqVzK7w AMWObNqflcGCH4HS34lVb2Dz1ypFzCsZvRqR8AiQWYTKknzxWKn9zQkinKsuRiPaVYsa KGF59wy92bvzQ4yWuaiBD8z/B8jUMNNDj8UP+GSvvEVf3qfX2WrF0atn/OljvVjGHXPe lxJnP4LqWy2mEPYGPVuiA2Ur1QX/KWMSXZHxUrmO5kbaAwOmahCvC9Q21tKDLI3gIGcu /XGq8/wq9QE/tqj7wFKwLSxbTtkf5UZK86RMx05i8kmP/q5ONxXie8vYh9TPjYfllmnQ xmnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727295295; x=1727900095; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lqq1cNuC3bD2BpGXEYm7Tldi0hu4cGeS1oyzU9ngKpU=; b=OcbHFmGfXPwoNgIXTieHasdlEMIUDi6+NPBC197GDsMfJbU3vd1qa7g3SwD8zMbmGt SBu2b6fr9rsWHpU7c2s6hZj9CFr7O6RZXtAATfcNJkNC+t6f/RR1O3TpQ22DRs1XiMO+ UgIdQ9M12GUafv+ONgx1hoMFh1akX7q67ou7LenXHF/kK9/yAg4RbB9tYgHze2i+Rw7/ xaCYE8K0UY1n8mcWHduhixorbIA4qWsjStAh0pYTZy0nPyXBke0F8OROLR0XuiYCRznS XXcW7xUd4WTAG9In4/51VOScZAomJTHFQcd/kghSw3r1sVYg1EoJxf+jK0gEaDmiwm4n qZQw== X-Forwarded-Encrypted: i=1; AJvYcCV5uiho5nRx+1bz9Mrq5kIR1/sX5ln+eSitN0Tl++lgmk5w1l3EgFTW6AsSMOKMS2izYBlWt++NjRxtbQ==@python.org X-Gm-Message-State: AOJu0Yzy/Iwh2jyCRutPNKGT7bFAGgJp5WMc2anBLqKRXWT55d/bEGZL 0BkNWGCbEpObwP7OyaboAAcHOg6zO4ydFW3HFPrGiAerEC3akBlSRfWDRl+strB8WCWSkcS5H3u pKU6Q4RQF23+T0Fmiy3HGCuGQeVU= X-Google-Smtp-Source: AGHT+IEl0aBbnDKnqr02OL2XGfHRF/DAMHsNY7wawU5gGIgM34pv95usqnK0UV3lPH0E2jv1PTW/IZsnoy2WlzWY114= X-Received: by 2002:a05:622a:410:b0:457:f8b1:a03a with SMTP id d75a77b69052e-45b5dedf080mr54678961cf.24.1727295294868; Wed, 25 Sep 2024 13:14:54 -0700 (PDT) In-Reply-To: <CAGJtH9RBmcofpg5ifiXZm4z8XRBQkGVzDSduR7=9QH75-Ubpgw@mail.gmail.com> X-Mailman-Approved-At: Thu, 26 Sep 2024 11:16:28 -0400 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: <CAJQBtgmtB-Qxv2t+w41nkH6vgTTj9_JV7UEUuQS3hZUc6PBe5A@mail.gmail.com> X-Mailman-Original-References: <CAGJtH9RBmcofpg5ifiXZm4z8XRBQkGVzDSduR7=9QH75-Ubpgw@mail.gmail.com> Bytes: 6516 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=E2=80=AFPM 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 =3D threading.Thread(target=3D self.some_func(), args=3D( ...,), = ) > thread1.start() > # kill the thread > event_thread1 =3D 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