another thread on Python threading

Steve Howell showell30 at yahoo.com
Sun Jun 3 17:52:59 EDT 2007


--- "cgwalters at gmail.com" <cgwalters at gmail.com> wrote:
> One random idea is to for Python 3000, make the
> equivalent of
> __slots__ the default, *but* instead gather
> the set of attributes from all member variables set
> in __init__.  

Are you suggesting to do this at startup time or
runtime?

The pitfall here is that to reduce code duplication,
you might initialize certain variables in a method
called by __init__, because your object might want to
return to its initial state.  An example might be an
object that flipflops between waiting for headers and
waiting for payloads.  You might have code like this:

class MessageReader:
    def __init__(self, incoming_port):
        self.incoming_port = incoming_port
        self.start_waiting_for_headers()

    def start_waiting_for_headers(self):
        self.waiting_for_headers = ''
        self.header = ''
        self.payload = ''

    def handle_payload(self):
        self.do_something_with(self.payload)
        self.start_waiting_for_headers()

    # ...





       
____________________________________________________________________________________
Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
http://farechase.yahoo.com/



More information about the Python-list mailing list