Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'exit': 0.07; 'terminated': 0.07; 'python': 0.09; 'blocked': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'termination': 0.09; 'thread,': 0.09; 'threads.': 0.09; 'thread': 0.11; '(special': 0.16; 'boolean': 0.16; 'dangling': 0.16; 'invoking': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'somehow,': 0.16; 'threading': 0.16; 'threads': 0.16; 'previously': 0.18; 'input': 0.18; '(or': 0.18; 'libraries': 0.22; 'task': 0.23; "i've": 0.23; 'external': 0.24; "doesn't": 0.28; 'header:X-Complaints-To:1': 0.28; 'worked': 0.30; 'etc.)': 0.32; 'switch': 0.32; 'url:home': 0.33; 'to:addr :python-list': 0.33; 'likely': 0.33; 'operations': 0.33; 'recommended': 0.33; 'sequence': 0.35; 'continue': 0.35; 'received:org': 0.36; 'but': 0.36; 'method': 0.36; 'charset:us- ascii': 0.36; 'being': 0.37; 'subject:: ': 0.38; 'possible.': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; "you've": 0.61; 'risk': 0.66; 'middle': 0.66; 'cooperative': 0.91; 'dennis': 0.91; 'received:108': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: QThread.terminate in Python 3 Date: Sun, 23 Sep 2012 13:58:36 -0400 Organization: > Bestiaria Support Staff < References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-79-217-201.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348423115 news.xs4all.nl 6934 [2001:888:2000:d::a6]:55947 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29836 On Sun, 23 Sep 2012 20:39:11 +0430, Lee Harr 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/