On Sat, Feb 12, 2011 at 9:53 AM, Chris McDonough <chr...@plope.com> wrote:
> On Sat, 2011-02-12 at 09:43 -0800, Mike Orr wrote: > > On Wed, Feb 9, 2011 at 2:46 PM, Tres Seaver <tsea...@palladion.com> > wrote: > > > One bit I noticed: In > > > > https://bytebucket.org/sluggo/pyramid-docs/wiki/html/migration.html#app-globals-and-cache > , > > > you state:: > > > > > > You can also use ordinary module globals or class attributes, > > > provided you don’t run multiple instances of Pyramid applications in > > > the same process. (Pyramid does not encourage multiple applications > > > per process anyway. Instead Pyramid recommends its extensibility > > > features such as its Zope Component Architecture, which allow you to > > > write pieces of code to interfaces and plug them into a single > > > application.) > > > > > > Pyramid actually goes out of its way to make running multiple apps in > > > the same process work: in fact, it uses the ZCA in a way which means > > > that registrations made in one app's configurator won't interfere with > > > those made in another app's configurator. Perhaps the docs need to > show > > > an example of such a setup, but it is quite supported. > > > > > > Some of us *do* write apps that expect to be extended / reconfigured > via > > > the ZCA registry, but Pyramid itself doesn't mandate that (or even > > > document it all that well). If such an app uses the "global" ZCA APIs, > > > it won't benefit from Pyramid's segregated registries, but that is no > > > different from use of any other global (module- or class-scope > > > variables, etc.) > > > > I just got back from my trip. So what's the official recommendation > > for arbitrary global variables? I just wrote what I thought would be > > safe. But people have their database connections and other things > > they'll have to put somewhere. Should I say to put them all in the > > registry? Under Settings? As module globals? > > I've been suggesting that folks put them in registry.settings. > > > > > If they do want to put something into the registry, what's the syntax? > > It's the ZCA API. I wouldn't suggest that folks use it to store simple > application-scoped values. > > > Can you just assign an attribute in 'registry'? > > You can do this as well, although if you assign the "wrong" value it may > break the system. Better to use settings. > I just tackled this in my own extension to Pyramid/BFG, and am doing it by making an AppConfig object that gets attached to the request using the slick new reify decorator on a custom request factory. My particular AppConfig object does looks first in the database for config key, second at it's own attributes, and third at the settings dict, my figuring being that should be the order of overrides. Seems like a good setup to me as the AppConfig object is guaranteed to be instantiated once and only once on request startup, but can look in the registry for server start up values when it gets instantiated. Then it sits there as an attribute of request and is available to everything else in the system. If I need to have a global grab something from the WSGI env, it can do so easily in it's instantiation, and it's lifecycle is tightly controlled, but the whole rest of the app/framework knows to always grab globals by doing request.config.get('key') If someone wants to see code, I can post it. It's simple but might be useful. I'm no ZCA expert though so if this is a bad plan for some reason I'd love to hear it. iain -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To post to this group, send email to pylons-devel@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.