On Sun, 2009-04-12 at 22:22 -0700, Mike Orr wrote: > > On Sun, Apr 12, 2009 at 9:18 PM, Iain Duncan <[email protected]> wrote: > > > > I've been working through the Pylons book and new docs ( fantastic > > improvement btw! ) as well as Ian's webob tutorials. I'm pretty clear > > now on how Pylons calls pylons controllers and wsgi apps, and understand > > the difference between calling an instantiated app and the way pylons > > re-instantiates a controller on each request. However I haven't seen > > anything describing *why* pylons does it this way. I'd like to learn > > more, so is there an explanation as to why that's a good idea anywhere? > > It's just a design variation. Instantiating a controller for each > request allows you to put request-local state data in 'self'. (As if > 'c' and 'request' weren't enough.) It also guards against > accidentally leaking state from one request to another. I believe > that has been the experience with previous frameworks, that > instantiating the controller for each request is a good thing. Pylons > has plenty of places to store multi-request data anyway: app_globals, > cache, and module globals. And the controller *class* is a module > global so it also remains in memory. > > As for why external WSGI applications are long-lived, that's because > it's a complete application that manages its own requests. It may > have initalization state or database connections. It may be as big as > Plone. We don't know what it is, but we know that some WSGI > applications like to be long-lived.
Thanks Mike. I think in TG and in the web ob examples the standard is that controllers get instantiated once on startup and __call__'ed on request right? I'm curious, is the amount of extra python execution necessary trivial, or is this a valid way to trade execution time for ram use and vice versa? It seems to me that in a large app with many many controllers executing to fulfil each request ( say many components being amalgamated or something ) that one pattern would require a lot more code to stay loaded in memory and the other more to execute for each request. But maybe this is one of those instances where in reality the difference makes no difference? Thanks Iain --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
