[ZODB-Dev] Re: BTrees strangeness (was [Zope-dev] Zope 2.X BIG Session problems - blocker - our site dies - need help of experience Zope developer, please)

Chris McDonough chrism at plope.com
Wed Mar 3 22:36:47 EST 2004


On Wed, 2004-03-03 at 22:20, Casey Duncan wrote:
> > >         for key in list(self._data.keys(None, max_ts)):
> > >             assert(key <= max_ts)
> > >             STRICT and _assert(self._data.has_key(key))
> > >             for v in self._data[key].values():
> > >                 to_notify.append(v)
> > >             del self._data[key]
> 
> Maybe you could use items() and two loops instead;
> 
> to_rm = []
> for key, val in self._data.items(None, max_ts):
>     for v in val.values():
>         to_notify.append(v)
>     to_rm.append(key)
> for key in to_rm:
>     try:
>         del self._data[key]
>     except Keyerror:
>        pass # Somebody else deleted it first
> 
> I don't think that could raise a KeyError...

Well, the real bit of magic there is the "try.. except KeyError: pass"
stanza.  Believe me, I'm tempted to stick that in, but this is the kind
of voodoo that got me in to a lot of trouble in the older version of
this code (there was reams upon reams of voodoo in the old code), so I'd
really rather just figure out why the code is failing in the first
place.  I'd just rather not mask the problem until I understand the
cause.  That may never happen, of course, but a man can dream.

- C





More information about the ZODB-Dev mailing list