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


Groups > comp.lang.python > #78346

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

References (1 earlier) <mailman.14345.1411627213.18130.python-list@python.org> <871tr06nhs.fsf@elektro.pacujo.net> <mailman.14358.1411654608.18130.python-list@python.org> <87sijf69k5.fsf@elektro.pacujo.net> <CALwzidmjSJDMLCO2FTEw-OXrgmTbSx5zhMetC=k+H3+UGLGGww@mail.gmail.com>
Date 2014-09-26 02:04 +1000
Subject Re: ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.14362.1411661084.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Sep 26, 2014 at 1:40 AM, Ian Kelly <ian.g.kelly@gmail.com> 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

Back to comp.lang.python | Previous | Next — Previous 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