[Product Developers] listDAVObjects as a generator?

Martijn Pieters mj at zopatista.com
Fri Mar 30 14:02:12 UTC 2007


On 3/30/07, Tim Hicks <tim at sitefusion.co.uk> wrote:
> Does anyone see a problem with turning my custom type's listDAVObjects
> method into something like this?
>
>     def listDAVObjects(self):
>         """This may have unpleasant side-effects!  Turn this into a
>         generator that deactivates objects after they have been yield-ed.
>         """
>         for obj in self._tree.itervalues():
>             yield obj.__of__(self)
>             obj._p_deactivate()
>
> I've done limited testing, and things do seem to work - both in the
> sense of DAV access not breaking, and memory usage staying stable and
> low.  Is this a reasonable approach, or am I destined for trouble?

IIRC you may need to test for the objects active state before
deactivating, only deactivate those that were not active in the first
place, to minimize trashing cached objects used elsewhere:

def listDAVObjects(self):
    for obj in self._tree.itervalues():
        deactivate = getattr(obj, '_p_changed', True) is None

        yield obj.__of__(self)

        if deactivate:
            obj._p_deactivate()

-- 
Martijn Pieters




More information about the Product-Developers mailing list