[Zope] Re: [Warning] Zope 3 component architecture (CA) not
reliably usable for registrations from Python
Martijn Faassen
faassen at startifact.com
Wed Jan 10 05:45:31 EST 2007
Dieter Maurer wrote:
> I tried to use Zope3 events to get informed when requests start and end.
>
> One of our modules (the interface module to "jpype") requires such
> a notification for reliable work. Therefore, it tried to register
> the corresponding subscriptions on import of this module.
> Unfortunately, this works very unreliably -- for the following reasons:
>
>
> The CA performs by itself only extremely minimal initialization.
> Especially, it does not register the "Adapters" service, necessary
> for the registration of event subscriptions.
>
> The full CA initialization is only performed quite late, in the call
> to "Products.Five.initialize".
> Event notification registration attempts before this time will fail
> (with a "ComponentLookupError: 'Adapters'"),
> those performed after this time will succeed.
>
> The "Five" initialization is stupid enough that it will fail
> when the service registration for 'Adapters' has already been performed.
>
>
> At the current state, event notifications can reliably only be defined
> via ZCML. This is unfortunate for our use case where the registration
> should be bound to the import of a given module.
I'm a bit surprised why the huge [warning] is necessary. What I
understand you're saying is that you cannot use the component
architecture before it's done initializing. You also assert that you
need a registration to happen at Python import time. I'm curious to hear
more about why you need to do this - after all, you're talking about
listening to request start and end, and this happens after import time.
With Grok we have the grok.subscribe decorator which allows us to do this:
@grok.subscribe(IFoo, IObjectModifiedEvent):
def handle(obj, event):
... do something ...
The decorator gets executed during import time, but it doesn't actually
try registering anything into the CA. Instead it leaves an annotation on
the module and these annotations are read later (at "grok time", when
everything has been initialized) to make registrations in the component
architecture. Perhaps you can use a similar strategy. You could even try
taking a look at how we do this in Grok.
Regards,
Martijn
More information about the Zope
mailing list