Is there a simple way to register code for execution after each controller action has been executed?
Our problem is that most of our controller actions eventually obtain a pymongo connection object (from cache.ram) which itself pools connections internally and are thread-safe. These connection objects need to have end_request() called to free up their internal connections. We were originally calling end_request() everywhere a pymongo connection was obtained but that doesn't work for nested invocations, and it's hard to balance when exceptions occur. Would it be better to write a decorator and wrap the controller action with this? Any ideas and feedback much appreciated.

