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


Groups > comp.lang.python > #29836

Re: QThread.terminate in Python 3

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: QThread.terminate in Python 3
Date 2012-09-23 13:58 -0400
Organization > Bestiaria Support Staff <
References <SNT106-W454157727D0D514BB8AF91B19F0@phx.gbl>
Newsgroups comp.lang.python
Message-ID <mailman.1136.1348423115.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, 23 Sep 2012 20:39:11 +0430, Lee Harr <missive@hotmail.com>
declaimed the following in gmane.comp.python.general:

> I understand that use of QThread.terminate is discouraged,
> but it has worked well previously and I would like to continue
> this use if possible.
>
	And now you've encountered the reason it is discouraged.

	Pretty much ALL the threading libraries I've encountered discourage
arbitrary "killing" of threads. The recommended method is a cooperative
system by which the threads detect, somehow, a signal (special token on
an input queue, global boolean, thread-local boolean that can be set
external to the thread, etc.) and then clean up and exit "normally".

	Likely the presense of time.sleep() in the thread is providing: 1) a
task switch to the main thread (or whichever) is invoking the
termination and, 2) a clean thread state where termination doesn't risk
any dangling operations [the thread is blocked waiting for a signal to
continue] vs having a task switch occur in the middle of a sequence of
Python op-codes and then being terminated with an unfinished
statement...
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: QThread.terminate in Python 3 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-23 13:58 -0400

csiph-web