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


Groups > comp.lang.python > #68444

Re: Thread._stop() behavior changed in Python 3.4

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <felixonmars@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.05; 'subject:Python': 0.06; '*not*': 0.07; 'abuse': 0.07; 'versions.': 0.07; 'exits': 0.09; 'received:localnet': 0.09; 'snippet': 0.09; 'python': 0.11; 'def': 0.12; 'thread': 0.14; '3.3,': 0.16; 'abusing': 0.16; 'antoine': 0.16; 'boolean': 0.16; 'called,': 0.16; 'descriptor': 0.16; 'filename:fname piece:signature': 0.16; 'means.': 0.16; 'raised.': 0.16; 'skipped': 0.16; 'thread?': 0.16; 'underlying': 0.16; 'wrong).': 0.16; 'exception': 0.16; 'url:org)': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'basically': 0.19; 'starts': 0.20; 'import': 0.22; 'header:User-Agent:1': 0.23; '(or': 0.24; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'url:bugs': 0.29; 'related': 0.29; 'said,': 0.30; 'especially': 0.30; 'code': 0.31; '(since': 0.31; 'continues': 0.31; 'suites': 0.31; 'writes:': 0.31; 'file': 0.32; 'themselves': 0.32; 'run': 0.32; 'open': 0.33; 'url:python': 0.33; 'running': 0.33; 'monday,': 0.33; 'packaging': 0.33; 'skip:# 10': 0.33; 'totally': 0.33; 'noticed': 0.34; 'problem': 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'event,': 0.36; 'executing': 0.36; 'marks': 0.36; 'done': 0.36; 'doing': 0.36; "didn't": 0.36; 'method': 0.36; 'thanks': 0.36; "i'll": 0.36; 'possible': 0.36; 'hi,': 0.36; 'starting': 0.37; 'to:addr:python-list': 0.38; 'issue': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'improved': 0.60; 'skip:t 30': 0.61; 'new': 0.61; 'march': 0.61; 'myself': 0.63; 'telling': 0.64; 'here': 0.66; 'obvious': 0.74; 'antoine.': 0.84; 'improvement': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:user-agent:in-reply-to:references :mime-version:content-type; bh=Wd86lqvp6kC38SvIXM60PySaG7TS/AmAMF55EL+9boQ=; b=Pix1shHg89PyAXVCGsXsrccyoVaoyDVnc3LxcaZogC7yE4/iBIInr4Uy8cbcb2omEK PSOS3co/z/o4r9ejAPtpwikPc9V6edGfevAk47W13HEe05hR6yqbjvq0IarGZdMlMpss mDbdYdauplk1IqwV7TpPniB5qZjnSCFPxUUeGxKfTjrRzGRem72q7YrjJryRZ6Es42DG KW86z40yRKCqXum8hvdSLADNh2Cj3z4dPXI2SfWusMy3ul5k483/TJqzcwbPpeQjfTtk fdzqMiI5ptBBQYX+fN4096OWY8xnbTd15vgctzPNa1A57nBXq/8CC5VR205xdvjMDlmN V08A==
X-Received by 10.180.219.66 with SMTP id pm2mr10722224wic.60.1395079197738; Mon, 17 Mar 2014 10:59:57 -0700 (PDT)
From Felix Yan <felixonmars@gmail.com>
To python-list@python.org
Subject Re: Thread._stop() behavior changed in Python 3.4
Date Tue, 18 Mar 2014 01:59:52 +0800
User-Agent KMail/4.12.3 (Linux/3.13.6-1-uksm; KDE/4.12.3; x86_64; ; )
In-Reply-To <loom.20140317T182601-605@post.gmane.org>
References <279038900.uDlbjECTej@felix-arch> <loom.20140317T182601-605@post.gmane.org>
MIME-Version 1.0
Content-Type multipart/signed; boundary="nextPart1544915.Zz97aImPkM"; micalg="pgp-sha1"; protocol="application/pgp-signature"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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 <http://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>
Newsgroups comp.lang.python
Message-ID <mailman.8211.1395079205.18130.python-list@python.org> (permalink)
Lines 91
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1395079206 news.xs4all.nl 2862 [2001:888:2000:d::a6]:36432
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:68444

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Monday, March 17, 2014 17:33:09 Antoine Pitrou wrote:
> Hi,
> 
> Felix Yan <felixonmars <at> gmail.com> writes:
> > A minimized snippet to reproduce:
> > 
> > #!/usr/bin/python
> > import threading
> > 
> > def stale():
> >     import time
> >     time.sleep(1000)
> > 
> > t = threading.Thread(target=stale)
> > t.start()
> > t._stop()
> > 
> > This works correctly with Python 3.3, the program exits immediately after
> > t._stop() called, and no exception was raised.
> 
> Basically what you are doing is abusing a private method because you want
> to make the thread daemonic after it was started (a daemonic thread is
> not waited for at interpreter exit). Please do note one thing: the _stop()
> method does *not* actually stop the thread; it just marks it stopped, but
> the underlying OS thread continues to run (and may indeed continue to
> execute Python code until the interpreter exits).
> 
> So the obvious "solution" here is to mark the thread daemonic before
> starting it.
> 
> A possible related improvement would be to relax the contraints on
> Thread.daemon to allow setting the flag on a running thread?
> 
> That said, daemon threads (or abuse of the _stop() method as you did) can
> lead to instabilities and oddities as some code will continue executing
> while the interpreter starts shutting down. This has been improved but
> perhaps not totally solved in recent interpreter versions. A fully correct
> solution would involve gracefully telling the thread to shut down, via a
> boolean flag, an Event, a file descriptor or any other means.
> 
> (if you are interested in this, please open a new issue at
> http://bugs.python.org)
> 
> Regards
> 
> Antoine.

Thanks for the detailed explanation!

Actually I didn't used _stop() myself either, but noticed the problem when 
trying to build paramiko against python 3.4.

Thanks especially for the tip that the threads may be still running - actually 
I didn't even think about this part!

For now I just skipped the test suites for paramiko to get the packaging done 
(since the test suites themselves are passed without a problem, just the test 
script made something wrong). I'll try to follow up the issue for paramiko :)

Regards,
Felix Yan

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


Thread

Re: Thread._stop() behavior changed in Python 3.4 Felix Yan <felixonmars@gmail.com> - 2014-03-18 01:59 +0800

csiph-web