On Feb 16, 10:55 am, David Terrell <[EMAIL PROTECTED]> wrote:
> On Thu, Feb 14, 2008 at 07:59:04PM -0800, eching wrote:
>
> > When I use java servlets I often use the servlet context to store some
> > global objects that are accessible to all servlets in the container.
> > Is there an equivalent in web.py? I found a post from a couple years
> > ago that involved modifying web.py, but I'm not too keen on that. I
> > looked over the doc, but didn't see anything that quite matched.
>
> Do you really want sessions or real globals? That kind of thing can
> be a real bottleneck.
I've found servlet context attributes in java servlets immensely
useful for a number of things, so I was looking to do the same thing
with web.py. I am new to both python and web.py, so I don't know all
the possible implications.
>
> Here's a real simple example of something you could do if you really
> wanted to:
>
> import web
>
> def add_global_hook():
> g = web.storage({"counter": 0})
> def _wrapper(handler):
> web.ctx.globals = g
> return handler()
> return _wrapper
>
> class Hello:
> def GET(self):
> web.ctx.globals.counter += 1
> return "<h1>Counter: %d</h1>" % web.ctx.globals.counter
>
> if __name__ == '__main__':
> urls = ("/", "Hello")
> app = web.application(urls, globals())
> app.add_processor(add_global_hook())
> app.run()
>
> Note that it wouldn't work right in situations where requests are
> handled in different actual processes (mod_python with a forking
> MPM, forking FastCGI/SCGI handler, etc). Threaded will work fine.
Thanks for the example.
> --
> David Terrell
> [EMAIL PROTECTED]
> ((meatspace))http://meat.net/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to webpy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---