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


Groups > comp.lang.python > #78328

Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'subject:same': 0.07; '"if': 0.09; 'callback': 0.09; 'function,': 0.09; 'seemed': 0.09; 'random': 0.14; 'thread': 0.14; '24,': 0.16; 'statements,': 0.16; 'subject: \n ': 0.16; 'subject:run': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'code,': 0.22; 'case.': 0.24; 'skip:` 20': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'on,': 0.29; 'am,': 0.29; 'moved': 0.30; 'message-id:@mail.gmail.com': 0.30; 'submitting': 0.31; 'sep': 0.31; 'run': 0.32; 'checking': 0.33; 'sense': 0.34; 'subject:the': 0.34; 'something': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'i.e.': 0.36; 'subject:?': 0.36; 'project': 0.37; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'even': 0.60; 'future': 0.60; 'completed': 0.61; 'simply': 0.61; 'subject:skip:T 10': 0.68; 'results': 0.69; 'guaranteed': 0.75
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=qj4Ox5IpI3Xwu0RzIS6QKyYXs0utxa2iaG/Kca6nwrw=; b=WGpeGh6ZXoo8ADCsIIw3vR056U3Mf7ZEfAdKyAXyhz/vS05XpHy1AK6u85pwiHAxyJ GIqg4RvkuVkqf3KkoJufuF4JUtDQPhW5Te4EARSD/YaR+9WbZ0ylGBjqa+Hhuf2aPNEA VX/aRsvGSW67RvlSNwem8bGOlVMF1KgVn1JJiLCMb/xESYQQLkp5dfcJNHc8fs1q5BES b7P6g/iix1wdkK/HZLxTmLTyAK/M9WZcI9Jl3NfbZRPBURnaEUrSoVRy57dtosEuGZKw WH7hpOZ2ugPzMj7c9p30nh0B70X7+9N1bDMuye6IVrFDKUmue7cJBd3f4YPwlOf0IlMV 0XMw==
X-Received by 10.67.3.106 with SMTP id bv10mr15732870pad.13.1411627210798; Wed, 24 Sep 2014 23:40:10 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <e2f400e6-359e-4070-a822-d734e85e6a75@googlegroups.com>
References <e2f400e6-359e-4070-a822-d734e85e6a75@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 25 Sep 2014 00:39:30 -0600
Subject Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function?
To Python <python-list@python.org>
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 <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.14345.1411627213.18130.python-list@python.org> (permalink)
Lines 11
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1411627213 news.xs4all.nl 2847 [2001:888:2000:d::a6]:58989
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78328

Show key headers only | View raw


On Wed, Sep 24, 2014 at 8:44 AM, Praveen Gollakota <pgollakota@gmail.com> wrote:
> However, it seemed to fail when I removed the `time.sleep(random.random())` statements, i.e. at least a few `func` functions and `callbacks` **did not** run in the same thread.
>
> For a project that I am working on, the callback must always run on the same thread as the submitted function, so I wanted to be sure that this is guaranteed by TPE. (And also the results of the test without the random sleep seemed puzzling).

The documentation for Future.add_done_callback says: "If the future
has already completed or been cancelled, fn will be called
immediately." Checking the code, the callback is simply called from
the submitting thread in this case. This makes sense as the thread
that completed the future has already moved onto something else and
may not be readily available or even identifiable.

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


Thread

ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? Praveen Gollakota <pgollakota@gmail.com> - 2014-09-24 07:44 -0700
  Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? dieter <dieter@handshake.de> - 2014-09-25 08:14 +0200
  Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-25 00:39 -0600
    Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? Marko Rauhamaa <marko@pacujo.net> - 2014-09-25 12:46 +0300
      Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-25 08:16 -0600
        Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? Marko Rauhamaa <marko@pacujo.net> - 2014-09-25 17:47 +0300
          Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-25 09:40 -0600
          Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function? Chris Angelico <rosuav@gmail.com> - 2014-09-26 02:04 +1000

csiph-web