Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Knock, knock! Who's there? Sam and Janet. Sam and Janet who? Sam and Janet Evening...


comp / comp.lang.python / Re: How to stop a specific thread in Python 2.7?

SubjectAuthor
* How to stop a specific thread in Python 2.7?marc nicole
`* Re: How to stop a specific thread in Python 2.7?Stefan Ram
 `- Re: How to stop a specific thread (Posting On Python-List Prohibited)Lawrence D'Oliveiro

1
Subject: How to stop a specific thread in Python 2.7?
From: marc nicole
Newsgroups: comp.lang.python
Date: Wed, 25 Sep 2024 17:24 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: mk1853387@gmail.com (marc nicole)
Newsgroups: comp.lang.python
Subject: How to stop a specific thread in Python 2.7?
Date: Wed, 25 Sep 2024 19:24:49 +0200
Lines: 16
Message-ID: <mailman.7.1727285081.2990.python-list@python.org>
References: <CAGJtH9RBmcofpg5ifiXZm4z8XRBQkGVzDSduR7=9QH75-Ubpgw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de WuGaciXb0rBC/Not9/Hm+wM/mUlREf//rqPGjeG/xGLw==
Cancel-Lock: sha1:D3EWq6Tyku2uZWcA1ny589r5gYY= sha256:3dI6d1cvZDOoRDNmxSVTgJVdFXm8Bdw2houu3aXZrAk=
Return-Path: <mk1853387@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=VjjXpayO;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.046
X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'thread': 0.05; 'guys,':
0.09; 'subject:Python': 0.12; 'subject:2.7': 0.16; 'subject:stop':
0.16; 'subject:thread': 0.16; 'to:addr:python-list': 0.20; 'to:no
real name:2**1': 0.22; 'subject:How': 0.23; 'run': 0.23;
'thanks!': 0.24; 'sfxlen:2': 0.31; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; 'there': 0.33; 'received:google.com': 0.34;
'running': 0.34; 'from:addr:gmail.com': 0.35; 'want': 0.40;
'well': 0.65; 'skip:t 20': 0.66; 'following:': 0.69; 'id)': 0.84;
'subject:specific': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1727285078; x=1727889878; darn=python.org;
h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
:date:message-id:reply-to;
bh=agPmndtBjb1STkxD/IW21k6CTBaFKa0SX9ihmaECSPs=;
b=VjjXpayOmHU9QLvogHgFQsQ6K0qsfvw3F0yM6/RBVxQVEe5gA3nxfiueCzPPcusygh
jV1BIT+7evSanDSJ1dD18mqBvwT7PgHxU5J0eafHXUB27Q/nEV4jXBOZG77vJ6UJzY0X
+W23Qf0CiCZTqJGcHbnTdZbzzdw9XUwZsiNj7chqne0XoK+V/i8y0heZHs4Z3GQjxUhW
1ElYEDY4K46ht6TH6u4vKCAwJLotFJHuLQ5K36EKJi7yNMOsUi3rJidmkAASLcfP8zoV
F9a8chnOmNQ2g7nwrp4BbWatMVLWq/RIcJnaEhspfgTOIzuXme93Bmyy79urWSoDaDJ8
lc9g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1727285078; x=1727889878;
h=to:subject:message-id:date:from:mime-version:x-gm-message-state
:from:to:cc:subject:date:message-id:reply-to;
bh=agPmndtBjb1STkxD/IW21k6CTBaFKa0SX9ihmaECSPs=;
b=cQVyldIEHgTlAutH1cfoGdtMTCv4CmWfTqXK0rvW+omY5CWSbLQdQsBoLBFmD/PrJk
XXBI3NM6/MRLumTbfKb2q2L7oPkibgt3p1gRef/37B+moyaloqzM3nLygMocc+F1jPnT
elIdlSQ3lJsvStY7AnmRau5vZcWMXSQ6BVM1br4vTnU+Cn4x9R+5HW6n+XoqOSDmflr9
S8EoJN/ZaV97+0LYJo3t0F36LxYj7oGu/Y3nUeRi9ww7vgP0lw7dxuHlQPlo+E+0t2V4
lbefVPzhyjiHKFthkinKSR8aD75AVQOTj3tbpoa/6MsdAFrVApmKvvampoDieYZm65TZ
RDXA==
X-Forwarded-Encrypted: i=1;
AJvYcCVICTQUm4vGZUXWxSlNq1fOc0QcxkALc/Ds1BoRdWm+S/rulee/VPOjWs1m++CE6JwlnkB2KtE1uezvKA==@python.org
X-Gm-Message-State: AOJu0Yzq9QPmHKJe+HiGz5uVbjGisnJ7X6/WTayXI/81/y0edokuTgBX
s1W34SkC9mEmsYM2yiOiVNix/PhB5vuGk425UgvQha1CYEyWloEsBYNaWdgS0VHuGqsOVY6ZaS3
P2yayi8fDa3h9qT6/KBnMFnnjSFPeGwhx
X-Google-Smtp-Source: AGHT+IH2bhCPkwalO+I08c+qx3FW/FHwWZx4wuWGVhdsJKtiGfi3wcyqwrtzENYNgwgp0NSdwO6eRSfAcIoRXMggL9Q=
X-Received: by 2002:a05:690c:d8b:b0:6b0:e813:753b with SMTP id
00721157ae682-6e21d9f10c0mr36884497b3.38.1727285078196; Wed, 25 Sep 2024
10:24:38 -0700 (PDT)
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <CAGJtH9RBmcofpg5ifiXZm4z8XRBQkGVzDSduR7=9QH75-Ubpgw@mail.gmail.com>
View all headers

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!

Subject: Re: How to stop a specific thread in Python 2.7?
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Wed, 25 Sep 2024 17:39 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: How to stop a specific thread in Python 2.7?
Date: 25 Sep 2024 17:39:37 GMT
Organization: Stefan Ram
Lines: 10
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <threads-20240925183826@ram.dialup.fu-berlin.de>
References: <mailman.7.1727285081.2990.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de E8ssBS2SjqigyVdiwh5r6gHl7+n6eeWtVeRPge92iro7vr
Cancel-Lock: sha1:W46qQYidg5XQQQ6X6XxZDJmp65w= sha256:iXnIMuziBUlIcI6NNokbX8C/0Z1w9eimsvP3vetFw7k=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

marc nicole <mk1853387@gmail.com> wrote or quoted:
>I want to know how to kill a specific running thread (say by its id)

Killing or stopping a thread can cause data corruption and
unpredictable behavior. It's better to use a more chill
approach like setting a flag to let the thread know when to
wrap it up and exit gracefully. If you really need to terminate
something abruptly, go for a process instead of a thread.

Subject: Re: How to stop a specific thread (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Wed, 25 Sep 2024 21:42 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: How to stop a specific thread (Posting On Python-List Prohibited)
Date: Wed, 25 Sep 2024 21:42:10 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <vd203h$3r2r4$9@dont-email.me>
References: <mailman.7.1727285081.2990.python-list@python.org>
<threads-20240925183826@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 25 Sep 2024 23:42:10 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d676190ddbdcb7173a64dc657b0df900";
logging-data="4033380"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18o7VrJ1Fo0MgiDzXYcyn+i"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:0yZkvVcuQ1APt/78v3aQS93qPlw=
View all headers

On 25 Sep 2024 17:39:37 GMT, Stefan Ram wrote:

> Killing or stopping a thread can cause data corruption and
> unpredictable behavior.

Interesting that even the underlying POSIX thread-terminating call
<https://manpages.debian.org/3/pthread_cancel.3.en.html> allows for the
concept of “cancellation points”, so that threads can elect to only be
terminated at well-defined points in their execution.

1

rocksolid light 0.9.8
clearnet tor