[Zope-Coders] Fw: [Zope] sessions and zope2.6.0

Tim Peters tim@zope.com
Tue, 22 Oct 2002 14:21:33 -0400


[Chris McDonough]
> This is almost certainly the problem in my code (obviously).

It easily accounts for not deleting all the keys you expected to delete, and
for deleting keys beyond the end of the original range.  But it's not
obvious that it accounts for data[k] ever raising KeyError -- no matter how
damaged the relationship between the iterator and the tree, the iterator
should still return *some* key in the object.  Unless maybe a bucket gets
unlinked from the tree entirely (because it becomes empty), which would
leave the iterator pointing into a bucket chain that's no longer part of the
tree at all.

Anyway, in Zope3 I'd urge people to use the (new in Zope3) iterkeys()
methods of BTrees and Buckets instead.  Like the Python dict iterkeys(),
those do lazy iteration over BTrees and Buckets (BTree keys() acts like dict
iterkeys() now, but Bucket keys() acts like dict keys() now, and now there
isn't a way to do lazy iteration over a Bucket).  So it's more obvious that
way.  The iterkeys() implementation also has *some* "oops! the bucket
changed size!" safety checks.

> We'll see how listifying this piece does in practice.

Or use tuple() instead of list(), if you're keen to save a little memory.

> You're my hero. ;-)

Thank you for giving me a reason to live <wink>.