Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.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.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'subject:same': 0.07; 'callback': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'block.': 0.16; 'enough.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imo.': 0.16; 'recipe': 0.16; 'subject: \n ': 0.16; 'subject:run': 0.16; 'wrote:': 0.18; 'stack': 0.19; 'examples': 0.20; 'not,': 0.20; 'example': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'cc:2**0': 0.24; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'argue': 0.31; 'sep': 0.31; 'probably': 0.32; 'fri,': 0.33; 'subject:the': 0.34; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'moving': 0.39; 'either': 0.39; 'above,': 0.60; 'ian': 0.60; 'simply': 0.61; 'simple': 0.61; 'further': 0.61; 'more': 0.64; '26,': 0.68; 'subject:skip:T 10': 0.68; 'isolate': 0.84; 'to:none': 0.92; 'imagine': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=MpaosjTESuZypng15bHUd3nnm6X5ANQKiw/7xzuOtkw=; b=Q5/L3Z46D1QybL4PmyxWGlaSrS8eBLeLrqKpOslG9eI7d1KxzzO4n+dRjZVvBuycrh mKzcLf0qyiNURR70amdXDc9I4nlO4BmMLEXYsp9AJBnCXp7taGF3slF8cW6Fas/9gCyb pvRJvNGnQrX3jp2hV0vVufVbM4xkizoJl5NP32OzQwZUNGiSPRwd+JP15twjyBPw8/Qm Qh5ER/2+Qe8yJRjHdr8rxkPWbsXRtYlV5+HMNKflsmhGbeJ565cCzntFrNFH2JvLU0CW X43DmC8NwoiPE1OA4d1Hx4jnI6H2IjsyHnBK9fsFGAUW8Uagk77u+24KP9U3HhGBtzYf XqyA== MIME-Version: 1.0 X-Received: by 10.42.92.129 with SMTP id t1mr19514471icm.59.1411661080990; Thu, 25 Sep 2014 09:04:40 -0700 (PDT) In-Reply-To: References: <871tr06nhs.fsf@elektro.pacujo.net> <87sijf69k5.fsf@elektro.pacujo.net> Date: Fri, 26 Sep 2014 02:04:40 +1000 Subject: Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? From: Chris Angelico Cc: Python Content-Type: text/plain; charset=UTF-8 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411661084 news.xs4all.nl 2957 [2001:888:2000:d::a6]:56033 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78346 On Fri, Sep 26, 2014 at 1:40 AM, Ian Kelly wrote: > Fair enough. In the simple example above, I see no harm in simply > moving the add_done_callback call outside (after) the "with self.lock" > block altogether. I can imagine more complex examples where the call > is further down the stack and harder to isolate from the lock, > although I would argue that's probably a code smell. I'd definitely call it code smell. What happens with this? with lock: def inner(): do_more_work() f.add_done_callback(inner) The lock's possibly released before the callback happens, or possibly not, but either way, the code *looks* as if it's all happening inside the "with lock" block. Recipe for confusion IMO. ChrisA