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


Groups > comp.lang.python > #86115

Re: Design thought for callbacks

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: Design thought for callbacks
Date 2015-02-22 15:54 +0200
Organization A noiseless patient Spider
Message-ID <8761au9hmr.fsf@elektro.pacujo.net> (permalink)
References (1 earlier) <mailman.18948.1424497381.18130.python-list@python.org> <87zj87i74p.fsf@elektro.pacujo.net> <mailman.19002.1424607035.18130.python-list@python.org> <87k2za9mbf.fsf@elektro.pacujo.net> <mailman.19010.1424612539.18130.python-list@python.org>

Show all headers | View raw


Cem Karan <cfkaran2@gmail.com>:

> You were saying that you move your objects into a zombie state.  I
> assumed that you meant you marked them in some manner (e.g., setting
> 'is_zombie' to True),

Yes, but even better:

    self.set_state(ZOMBIE)

>  so that anything that has a strong reference to the object knows the
>  object is not supposed to be used anymore.

The other way round: the zombie object knows to ignore callbacks sent
its way. It's not the responsibility of the sender to mind the
receiver's internal state.

I nowadays tend to implement states as inner classes. Here's how I've
implemented the zombie state of one class:

class Delivery...:
    def __init__(...):
        ...
        class ZOMBIE(STATE):
            def handle_connected(self):
                pass
            def handle_eof(self):
                pass
            def handle_response(self, code, response):
                pass
            def handle_io_error(self, errcode):
                pass
            def zombifie(self):
                assert False
            def transaction_timeout(self):
                assert False


Marko

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


Thread

Re: Design thought for callbacks Chris Angelico <rosuav@gmail.com> - 2015-02-21 16:42 +1100
  Re: Design thought for callbacks Marko Rauhamaa <marko@pacujo.net> - 2015-02-21 18:03 +0200
    Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 07:10 -0500
      Re: Design thought for callbacks Marko Rauhamaa <marko@pacujo.net> - 2015-02-22 14:12 +0200
        Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 08:42 -0500
          Re: Design thought for callbacks Marko Rauhamaa <marko@pacujo.net> - 2015-02-22 15:54 +0200

csiph-web