quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Graham Dumpleton" <grah...@dscpl.com.au>
Subject Re: glue between apache and python logging
Date Fri, 21 Oct 2005 05:21:15 GMT
Nick wrote ..
> Graham Dumpleton wrote:
> >>Graham Dumpleton wrote:
> > Unfortunately you can't do that as all Python request objects in that
> > chain are created fresh for the handler which is the target of the
> > internal redirect. When the internal redirect returned, the cached
> > would then be actually different to the original. It would still return
> > the same underlying Apache data, but any extra stuff added to the
> > request object from Python code wouldn't be accessible.
> The cleanup routine gets called at the end of each request, so I don't
> think that's an issue that couldn't be resolved with the method I was 
> describing.  Perhaps I was being too simplistic in my example to fully
> explain what I was thinking, though.
> But in any case, I think the problem could be solved much more simply by
> changing the following code:
>      def set_req(self, req):
>          prev_req = self.local.req
>          self.local.req = req
>          def free_req():
>              self.local.req = prev_req
>          req.register_cleanup(free_req)
> That should take care of restoring the previous "cached" request object
> without explicitly creating a stack (i.e. relying on the Python call 
> stack to bind local variables in the closure).

Yeah, that would work. Quite cute actually.

It is only recently that I realised that a nested function like that
could access stack variables of the enclosing function. Might look
at changing how I do things to use this method and eliminate
my use of the list as a stack.



View raw message