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?

References <e2f400e6-359e-4070-a822-d734e85e6a75@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2014-09-25 00:39 -0600
Subject Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function?
Newsgroups comp.lang.python
Message-ID <mailman.14345.1411627213.18130.python-list@python.org> (permalink)

Show all headers | 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