[Zope-dev] Running methods on Zope startup.

grahamd@dscpl.com.au grahamd@dscpl.com.au
Wed, 24 Apr 2002 21:56:52 -0600 (MDT)


Is there a Zope product out there which implements a "Startup" like folder
for Zope? That is, I want to be able to have a folder like object called
"Startup" in the root directory, and when Zope is first started I want
Zope to automatically make a call against the "Startup" object which could
then in turn run methods of any user defined objects which have been added
into the "Startup" folder to perform special processing only when Zope is
started.

Imagine a situation similar to database connections. With database connections
when you create it you can indicate that you want the connection established.
Now when Zope is restarted, those database connections will be automatically
restarted when Zope restarts. Although, I am not sure whether this is when
Zope actually starts or when the next request using that database happens.

Anyway, I ultimately want to be able to have a Zope product which has a
persistent interprocess messaging connection to another process. Although
when first added into Zope the connection can be initiated, I know of no
way to have Zope restart that connection when it restarts. I can't rely on
the connection only starting when someone tries to access the resource, I
want it to happen straight away upon Zope restart.

When I thought about it, I figured the most basic thing to do would be to
have a Zope "Startup" folder as described in a known place. I could then
stick in that folder, methods to be triggered at startup which could startup
the interprocess communications link for me. This seemed better than having
a startup mechanism specific to what I was doing as it could be used for
other things as well.

Can anyone point me to such a Zope product. I have started looking at how
to do it myself and have some of the bits in place. The first issue is that
when the "initialize()" method in the product "__init__.py" file is called
not all Zope startup has occured, so it is too early to trigger things from
that point. Best I could come up with there was to register a callback to
asyncore to be called when asyncore mainloop is actually run, which is after
all Zope startup has been done.

The next problem is getting an appropriate context to be able to start making
calls into Zope objects. The "initialize()" method gets a product context,
but doesn't have public access to the application context. Is there some way
of accessing the Zope application context and thus root folder where you
don't otherwise have a handle to it? Can Main.bobo_application be used?

Even if the application context is obtained, is it safe to be making calls
into Zope objects from a callback from asyncore? Is there a better way?

I am very new to Zope and this is my first adventure into making a Zope
product and thus could be totally off track. If anyone understands what
I am trying to do and can suggest how to do it or point at something that
does what I want, then even better.

Personally I would be surprised if this hadn't already been done or even
that there is some inbuilt way of doing it now, as it opens up all sorts of
interesting possibilities.

Appreciated if responses are cc'd to me as well as going to the list as I
am not a member of the list yet and am using list archives.

Thanks in advance.

--
Graham Dumpleton (grahamd@dscpl.com.au)