Hi all,
    I'm trying to use extensively the scheduler for an application.

There are a few things I can't wrap my mind around.... the first, simplest, 
is how to setup DEBUG logging level on the scheduler when started as 
"python web2py.py -K appname" ....

Second, and there's the "advanced" part, at least for me: if you want to 
use scheduler, you must istantiate it on a model file.
Until now I was firing some functions and I was happy with that......
Now I need to launch function that are "contained" in classes defined in 
modules.....

My models/scheduler.py it's like this:

from gluon.scheduler import Scheduler
from mymodule import SomeClass

def myonlyfunction():
      myclass = SomeClass(db)
      return myclass.do_work()


myscheduler = Scheduler(db, dict(myonly=myonlyfunction))


Everything is working smoothly, but for every task the Scheduler runs, 
myclass is istantiated (obviuosly).
I'd like to istantiate the class only once, when the Scheduler is 
started.... how to do that ?

The "normal" way in python programs I did before was to move the class 
"istantiation" as a global object:


from gluon.scheduler import Scheduler
from mymodule import SomeClass

myclass = SomeClass(db)

def myonlyfunction():
      return myclass.do_work()


myscheduler = Scheduler(db, dict(myonly=myonlyfunction))

But doing that in web2py resorts in an istantiation every time a page is 
called (models file are executed for every request, I know)....

Someone faced that before and has a solution ?

Many thanks in advance to all

Niphlod

Reply via email to