Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:two': 0.07; '"c"': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'language,': 0.12; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'spawn': 0.16; 'subject:between': 0.16; 'this)': 0.16; 'threads,': 0.16; 'prevent': 0.16; 'code.': 0.18; 'header:User-Agent:1': 0.23; 'large,': 0.24; 'first,': 0.26; 'code:': 0.26; 'header:X -Complaints-To:1': 0.27; 'function': 0.29; "d'aprano": 0.31; 'steven': 0.31; 'writes:': 0.31; 'run': 0.32; "i'd": 0.34; 'problem.': 0.35; '(2)': 0.35; 'but': 0.35; 'really': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'two': 0.37; 'level': 0.37; 'to:addr:python-list': 0.38; 'short': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'hope': 0.61; 'received:217': 0.63; 'different': 0.65; 'other.': 0.75; 'completes': 0.84; 'computation.': 0.84; 'listening,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: dieter Subject: Re: Dynamically swapping between two algorithms Date: Wed, 24 Sep 2014 09:44:26 +0200 References: <54218831$0$29979$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e0b8d3.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:7CrVVaJKaqh7z6NGIexhJ4urVEg= 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411544682 news.xs4all.nl 2897 [2001:888:2000:d::a6]:41639 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78268 Steven D'Aprano writes: > ... > *If* Python was a different language, I would spawn two threads, one using > SHORT and the other using LARGE, then which ever completes first, I'd just > kill the other. Alas, this won't work because (1) the GIL The GIL does not prevent this scenario. The two threads will not really run in parallel but interleaved - but this should not be a big problem. > and (2) you > cannot forcibly kill threads, only ask them to die and hope they listen. You can kill threads (though you will need a "C" level function for this) as long as they execute Python code. And it is your code: you can make your threads be listening, from time to time in the computation.