Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'output': 0.05; 'subject:Python': 0.06; 'function:': 0.09; 'def': 0.12; 'thread': 0.14; 'antoine': 0.16; 'broken.': 0.16; 'called.': 0.16; 'concurrency,': 0.16; 'doubly': 0.16; 'wrote:': 0.18; 'all,': 0.19; "python's": 0.19; '>>>': 0.22; 'import': 0.22; 'print': 0.22; "aren't": 0.24; 'stopping': 0.24; 'mon,': 0.24; "i've": 0.25; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'apparently': 0.31; 'run': 0.32; 'says': 0.33; 'could': 0.34; "can't": 0.35; 'test': 0.35; 'received:google.com': 0.35; 'curious': 0.36; 'starting': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'removing': 0.60; 'truly': 0.60; 'skip:t 30': 0.61; 'simply': 0.61; 'first': 0.61; 'mar': 0.68; 'obvious': 0.74; 'lack': 0.78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=w3R0V3oc2qQjga+yWd6PZFQpWn9qaQan5FQ2IIvk6Sg=; b=R07J4bIc3DlJonuQbx4sYTTakFRsPX4JpvnRE4RtZ7Em3kmxSiNkIvcyUmIjlwKH3P Uy37GkjEetYn+B/A9hrdxa3xnfejg98TBQXoaOTTwtf1aVTW4WGyhb/y17aecGpG25T5 1Rb6gqcUQaWURM/By2g1L54aGsSFvJUqZWzCZcq9T/Y2SYJtNrBGtbunH2+zrjXsVhey HY93hmTd17Uic9GWRV3zPbonrMYlKFKcj1FHMktLO/GrVsQQCajlyR+l4BX9Y7G3Siyt 191Pn+vG/n7/XS6F5pUTm2ShRPws1QjE/Pr+kuBWD7t38k4Nl7Qu+M33sDB0ul9l6d+1 BkJQ== X-Received: by 10.66.41.106 with SMTP id e10mr27758113pal.109.1395079471853; Mon, 17 Mar 2014 11:04:31 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <279038900.uDlbjECTej@felix-arch> From: Ian Kelly Date: Mon, 17 Mar 2014 12:03:51 -0600 Subject: Re: Thread._stop() behavior changed in Python 3.4 To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395079481 news.xs4all.nl 2922 [2001:888:2000:d::a6]:39835 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68445 On Mon, Mar 17, 2014 at 11:40 AM, Chris Angelico wrote: > Antoine says that this doesn't even stop the thread > (I can't say; I've never used _stop(), for obvious reasons), so this > code was doubly broken. I was curious about that -- after all, Python's threads aren't truly concurrent, so perhaps they could just test the flag each time they resume -- so I tested it using 3.3. First I tried simply adding a print call on to the end of the OP's function: >>> def stale(): ... import time ... time.sleep(1000) ... print('hello') ... >>> t = threading.Thread(target=stale) >>> t.start(); t._stop() No output was printed, so at least a sleeping thread can apparently be stopped. Then I tried removing the sleep call: >>> def stale(): ... for i in range(10): print('hello') ... >>> t = threading.Thread(target=stale) >>> t.start(); print('Starting'); t._stop(); print('Stopping') hello Starting Stopping >>> hello hello hello hello hello hello hello hello hello So yes, despite the lack of true concurrency, a thread can continue to run after its _stop has been called.