Re: about site specific initialization

Jacob Smullyan <[email protected]>
Newsgroups gmane.comp.web.skunkweb
Message-ID <[email protected]>
On Thu, 2004-07-29 at 04:28, Ren Bing wrote:
> Hi, all,
> 
> I have a simple question: my site depends on some init tasks to be done
> before any requests are answered, how can I do it? I think most of the sites
> will have something like this: parse config files, load dynamic objects,
> etc.
> 
> I understand that Skunk are forked after startup, so I need every process
> take the effect of the init work.

You probably should write a service to do this.  In the service, you can
either have the initialization take place at import or in a hook (the
latter is preferable).  There are hooks called ServerStart, which are
executed before the fork, and ChildStart, executed afterwards; if you
were creating external resources that couldn't be shared between
processes, you'd use ChildStart, and if you were parsing a config file
and turning it into ordinary Python data, you'd use ServerStart.

An example (untested):

  # myservice.py

  Config={}
  Resources={}

  def InitConfig():
      parseConfig(Config)

  def initConnections():
      magicalResourceInit(Resources)

  from SkunkWeb.Hooks import ChildStart, ServerStart

  ServerStart.append(InitConfig)
  ChildStart.append(InitResources)

Note that you aren't returning anything from these functions; if you
did, you'd stop the hook from continuing to execute.

To actually invoke the service, just add it to the list of active
services in sw.conf.

Hope that helps,

Jacob Smullyan


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.