> If I understand you correctly, I would just accept the
config arg inside
> do_something and use an internal "object
created" flag. The sessions
> module does something similar inside sessions.init:
>
> if not hasattr(cherrypy, "session"):
> cherrypy.session =
cherrypy._ThreadLocalProxy('session')
> if hasattr(sess, "setup"):
> sess.setup()
This is indeed exactly what I am trying to do.
>
> ...so that sess.setup() is only run once, on the first
request. Yours
> might look something like this:
>
> class Buffet(Tool):
>
> def __init__(self):
> self.o = None
> self._point = "before_finalize"
>
> def callable(self, customizable_arg):
> if self.o is None:
> self.o = Create_Once(customizable_arg)
> self.o.pull_trigger()
>
Hmmm... I guess I thought there was going to be a better way
to do
this. This solution just strikes me as functional but messy.
Shouldn't
instantiation code go inside the __init__?
In the interim, I've thrown together some code. Is there any
reason
not to do this:
class Buffet(Tool):
def __init__(self, customizable_arg):
self.o = Create_Once(customizable_arg)
self._point = "before_finalize"
self.callable = do_something()
def do_something(self): self.o.pull_trigger()
class Root(object):
def __init__(self):
cherrypy.tools.buffet = Buffet('cheetah')
cherrypy.config.update({'tools.buffet.on': True})
quickstart(Root(), ...)
-Bill Mill
bill.mill at gmail.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|