Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #196750 > unrolled thread

How to stop a specific thread in Python 2.7?

Started bymarc nicole <mk1853387@gmail.com>
First post2024-09-25 19:24 +0200
Last post2024-09-25 21:42 +0000
Articles 2 — 2 participants

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.


Contents

  How to stop a specific thread in Python 2.7? marc nicole <mk1853387@gmail.com> - 2024-09-25 19:24 +0200
    Re: How to stop a specific thread (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-25 21:42 +0000

#196750 — How to stop a specific thread in Python 2.7?

Frommarc nicole <mk1853387@gmail.com>
Date2024-09-25 19:24 +0200
SubjectHow to stop a specific thread in Python 2.7?
Message-ID<mailman.7.1727285081.2990.python-list@python.org>
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!

[toc] | [next] | [standalone]


#196754 — Re: How to stop a specific thread (Posting On Python-List Prohibited)

FromLawrence D'Oliveiro <ldo@nz.invalid>
Date2024-09-25 21:42 +0000
SubjectRe: How to stop a specific thread (Posting On Python-List Prohibited)
Message-ID<vd203h$3r2r4$9@dont-email.me>
In reply to#196750
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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web