Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed4a.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:same': 0.07; 'callback': 0.09; 'executed': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'thread': 0.14; 'function"': 0.16; 'function?': 0.16; '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; 'subject:run': 0.16; 'code.': 0.18; 'looked': 0.18; 'header:User-Agent:1': 0.23; 'question': 0.24; 'source': 0.25; 'skip:" 20': 0.27; 'header:X -Complaints-To:1': 0.27; 'writes:': 0.31; 'run': 0.32; 'quite': 0.32; 'subject:the': 0.34; 'could': 0.34; 'done': 0.36; 'charset :us-ascii': 0.36; 'subject:?': 0.36; 'should': 0.36; 'easiest': 0.38; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'tell': 0.60; 'details.': 0.61; 'received:217': 0.63; 'subject:skip:T 10': 0.68; 'guaranteed': 0.75 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: dieter Subject: Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? Date: Thu, 25 Sep 2014 08:14:26 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e0b82c.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:Q+9TvwTvAd7QdC1zx5u1/qiym8Q= 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411625683 news.xs4all.nl 2945 [2001:888:2000:d::a6]:51551 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78325 Praveen Gollakota writes: > In the ThreadPoolExecutor (TPE), is the callback always guaranteed to run in the same thread as the submitted function? To answer question of this type (yourself), you may look at the relevant source code. I am quite sure that the "submitted function" will be executed in one of the threads from the thread pool. I have not looked at the "ThreadPoolExecutor" code. The easiest thing would be to run the callback in the same thread as the submitted function. However, it could facilitate use of the "ThreadPoolExecutor" (less locking) when the synchronisation were done inside the "ThreadPoolExecutor" and the callbacks were executed in a single thread (likely the one which has set up the "ThreadPoolExecutor"). A look at the source should tell the details.