Re: Skunkweb-list digest, Vol 1 #357 - 5 msgs

Matthew Bogosian <[email protected]>
Newsgroups gmane.comp.web.skunkweb
Message-ID <[email protected]>
On Jul 29, 2004, at 20:36, [email protected] 
wrote:

> Subject: Re: [Skunkweb-list] about site specific initialization
> From: Jacob Smullyan <[email protected]>
> To: Ren Bing <[email protected]>
> Cc: [email protected]
> Date: Thu, 29 Jul 2004 10:47:13 -0400
>
> On Thu, 2004-07-29 at 04:28, Ren Bing wrote:
>> 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.
>
> ...

Ren,

This is probably not recommended (and I'd definitely consider going 
with Jacob's suggestion first for obvious reasons), but if you're 
looking for something quick and dirty, you can probably use the sw.conf 
file itself. It may not be the best place to do your application 
initialization (and it's probably a bad idea if you're developing 
something which can be installed and used by others), but if you just 
want to try something out, just tack a few lines onto the end of your 
conf file (or include your custom file from sw.conf):

     In sw.conf:

         ...
         # directive to include another conf file:
         # Include('/path/to/special.conf')

     In /path/to/special.conf:

         # do the initialization
         import foo
         import bar
         var = foo.init()
         bar.init(var)
         ...
         # clean up
         del var
         del bar
         del foo

I put the "del" statements at the end to keep the configuration 
relatively clean (otherwise it will have members called "foo", "bar" 
and "var").

Again, this is probably the wrong way to go about doing this (and 
probably not very efficient), but it may work as a quick hack. Hope 
this helps!

--Matt



-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
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.