On 5/10/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> I've written a python program that does some maintenance stuff on the
> computer.  It's really a stand alone program but I'd like it to be run
> at the beginning of every time I start TurboGears.  I figured I'd
> import it once, and it would run once upon startup of my TurboGears
> app.
>
> Since most of my editing is done in controllers.py, I put it there.
> It runs twice!
>
> Then I put it towards the beginning of start-myproject.py.  And then I
> tried the end.  It always runs twice.
>
> When called as part of a program I wrote (such as the test program
> below) it's only called once.
>
>
> #!/usr/bin/python2.4
>
> import mymodule
> print "hi"
>
>
> Where can I import my module so it only gets called once?

There's a "call_on_startup" list, where you can put a function which
should be called once at startup (as far as I can see).

I use it to load plugins in my blog software, gibe:

----------------------------------------------------------------------
def on_startup():
    for plugin_mod in pkg_resources.iter_entry_points("gibe.plugins"):
        mod = plugin_mod.load()
        ...
        p = mod()
        ...
        plugins[plugin_name] = p

from turbogears.startup import call_on_startup
call_on_startup.append(on_startup)

----------------------------------------------------------------------

Hope that works for you.

Cheers,

Neil
-- 
Neil Blakey-Milner
http://nxsy.org/
[EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to