[ZODB-Dev] ZEO ClientStorage's use of the asyncore main loop(was [Fwd: Re: [Zope3-dev] Twisted Publisher and Zope 2])

Tim Peters tim at zope.com
Fri Dec 9 16:09:49 EST 2005


[Jim]
> Historical note: asyncore didn't support private event loops either until
> I added the extra argument to the constructor.  I'm not sure why you need
> to pass the map to anything but the constructor.  Oddly. most, but not
> all of the methods that take a map, default to the one set in the
> constructor.  I don't really remember the details....

AFAICT, in 2.4.2 all asyncore _methods_ default to the map passed to the
constructor.  This isn't always dead obvious, but it's never truly subtle;
e.g., this is as bad as it gets:

    def set_socket(self, sock, map=None):
        self.socket = sock
        self._fileno = sock.fileno()
        self.add_channel(map)

The only trick there is that if you don't pass map= to set_socket(), it
passes None on to add_channel(), and add_channel() then uses self._map.

The asyncore _functions_ are a different story, but I suppose they have to
be.  You do have to pass a map to poll(), poll2(), loop() and close_all(),
else they'll use the module global socket_map.  But they aren't methods, so
have no way to know any better.

Also, AFAICT, this is all equally true in 2.3.5's asyncore.  It's OK to stop
being afraid of bad code in Python 1.5.2 ;-)



More information about the ZODB-Dev mailing list