this was super confusing to me for a while too, until i looked at some of 
my debug info and really understood the tweens.

iirc, the callstack is essentially:

* tween start
* `handler(request)` ( which can wrap other tweens )
* tween end
* response callback
* finished callback


the tweens are basically like python decorators or wsgi middleware .  even 
though they sound like a callback or some sort of "operation on a result", 
they're really just a logical block that wraps the action 
`handler(request)`.  

since your views are executed after all the tweens have begun , your 
callbacks haven't even been registered yet.


i may be in a similar situation as you -- i had some cleanup work being 
done in a tween , and it seemed to be creating some issues.

the idiom i've decided on now, is to do all my setup in the tween, but 
defer the cleanup to a finished_callback


it looks like this:

def my_tween_factory(handler,registry):
    def my_tween(request):
        try:
            request.add_finished_callback(my_cleanup)
            my_setup(request)
            response = handler(request)
            return response
        finally :
            log.debug('ok')
     return my_tween


-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-devel+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-devel.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to