[Zope-PTK] Re: [PTK(94)[1] request] Changing document views hard
Tres Seaver
tseaver@palladion.com
Sun, 11 Jun 2000 15:28:01 -0400
Martijn Pieters wrote:
>
> On Fri, Jun 09, 2000 at 08:17:11PM -0400, Tres Seaver wrote:
> > WRT Observable, I just checked in today a first cut at the
> > DefaultObservable
> > implementation. See $CVS_ZOPE/lib/python/OFS/DefaultObservable.py.
> > The interfaces are in the Interfaces wiki:
> >
> > <URL
> > http://www.zope.org/Members/michel/Projects/Interfaces/ObserverAndNotification>
> >
> > Adventurous souls can begin tinkering with it, and tell me
> > where I messed up :)
>
> Looking at the code, everything looks good to me. One point:
>
> Would it be a good idea if removing of a non-exisiting observer
> did not raise an exception?
>
> Imagine that a Observer first called unregisterObserver for itself on
> the Observable, then raised an exception. The Observable object then
> adds the Observable to the list of bozos, and afterwards tries to
> unregister the Observer, it has to eat the exception, but it doen't
> handle it.
>
> Either, the code unregistering should expect an exception, or the
> unregistering code should catch it and not let it pass on.
Good point! I don't mind having unregisterObserver() throw, but I
don't want to set up a race condition in the bozo-removal. How about
this patch:
for bozo in bozos:
- self._observers.remove( bozo )
+ try: # avoid race condition if unregister() called before now
+ self._observers.remove( bozo )
+ except:
+ pass
--
===========================================================
Tres Seaver tseaver@digicool.com
Digital Creations "Zope Dealers" http://www.zope.org