[Grok-dev] where to put the code that can be run automatically when groks are started up?

TonyXu txu at userful.com
Wed Apr 29 16:27:26 EDT 2009


Thank you, Wijbrand.

Your solution is perfect, and I have finished my task.

BTW, I have ever noticed the even mechanism, but I only read the Grok
official documentations, and they
don't mention the 'IDatabaseOpenedEvent' event. The lesson to me is that if
we can't find the answer
from grok's documentations, we should look for the answer from zope's.


Jan-Wijbrand Kolman-3 wrote:
> 
> Hi,
> 
> TonyXu wrote:
>> 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
>> program
>> can read the configuration from ZODB to initialize the scheduler thread,
>> and
>> start
>> 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:
> 
> 1)
> 
>   from zope.app.appsetup import IDatabaseOpenedEvent
>   from zope.app.appsetup.bootstrap import getInformationFromEvent
> 
>   @grok.subscribe(IDatabaseOpenedEvent)
>   def process_started(event):
>       db, connection, root, root_folder = getInformationFromEvent(event)
>       print 'DDD', event, db
> 
> 2)
> 
>   from zope.app.appsetup import IProcessStartingEvent
> 
>   @grok.subscribe(IProcessStartingEvent)
>   def process_started(event):
>       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.
> 
> regards,
> jw
> 
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
> 
> 

-- 
View this message in context: http://www.nabble.com/where-to-put-the-code-that-can-be-run-automatically-when-groks-are-started-up--tp23197488p23302192.html
Sent from the Grok mailing list archive at Nabble.com.



More information about the Grok-dev mailing list