I'm unfamiliar with beaker, so this is just a wild guess, but can you subclass beaker.session.Session
?
If so, then your new class could do its cleanup in __del__.
Something along these lines:
class MySession(beaker.session.Session):
def __init__(self, *args, **kwargs):
super(MySession, self).__init__(self, *args, **kwargs)
def __del__(self):
# your cleanup here
(Or maybe it's the expire
method that you need to define. Not sure, since I've never used beaker.)