[Zope-dev] SVN: zope.interface/branches/jinty-mem/src/zope/interface/interface.py Improve CPU performance of previous memory optimization

Brian Sutherland brian at vanguardistas.net
Thu Nov 11 03:50:24 EST 2010


On Tue, Nov 09, 2010 at 03:01:09PM -0500, Tres Seaver wrote:
> > I think the is a possible threading issue with Element.setTaggedValue
> > and Specification.subscribe - if two threads called the method
> > concurrently, then one of the values might be lost. I think the
> > correct way to do it would be:
> > 
> >     tv = self.__tagged_values
> >     if tv is None:
> >         tv = self.__dict__.setdefault('_Element__tagged_values', {})
> >     tv[tag] = value
> > 
> > This does bring the name mangling back though.

Thanks, I fixed the threading issue in Specification.subscribe. Given
that that part of subscribe is not run very often, I think we can live
with limited name mangling.

> I'm pretty sure we can safely neglect threading issues here:  no sane
> code will call 'setTaggedValue' except at import time, when we should be
> serialized by Python's own import lock.

Great, I quoted you on that ;)

The setdefault fix for the threading issue is not compatible with the
use of __slots__. I couldn't find another way to do it.

-- 
Brian Sutherland


More information about the Zope-Dev mailing list