[Grok-dev] where to put the code that can be run automatically when groks are started up?
janwijbrand at gmail.com
Wed Apr 29 03:26:23 EDT 2009
> Thank you for sharing your knowledge.
> It's so complicated that I need more time to understand it and I still don't
> know how I can implement my purpose.
> I think you might be able to help me.
> The scenario is that I have written a scheduler thread, and I want the
> can read the configuration from ZODB to initialize the scheduler thread, and
> the thread right after the Grok applications are started up.
I *think* it is quite a bit simpler than you might think. As far as I
know an event is send out when starting Zope - you can easily subscribe
to this event.
I investigated a bit and I think this would work:
from zope.app.appsetup import IDatabaseOpenedEvent
from zope.app.appsetup.bootstrap import getInformationFromEvent
db, connection, root, root_folder = getInformationFromEvent(event)
print 'DDD', event, db
from zope.app.appsetup import IProcessStartingEvent
print 'EEE', event # Do your stuff
There's a small issue with the second event subscriber; it is only fired
in projects build with the grokproject tool *before* it started using
paster. I think this actually is a bug in Zope. If it is I'll issue a
bug report for that.
I hope this helps.
More information about the Grok-dev