def on_transaction_end(session):
    '\n    Decorator for a function which should run after a top-level transaction ended.\n\n    Transactions that are either implicitly or explicitly committed or rolled back will be\n    closed at the end of a Pyramid view. This is here for cleaning up caches so that\n    code after the view, exception views for example, will not be able to access\n    detached instances.\n\n    Example usage:\n\n    .. code-block:: python\n\n       @util.db.on_transaction_end(session)\n       def flush_cache():\n           self._cache = {}\n\n    '

    def decorate(func):

        def _handler(_, transaction):
            if (transaction.parent is None):
                func()
        sqlalchemy.event.listen(session, 'after_transaction_end', _handler)
        return func
    return decorate
Decorator for a function which should run after a top-level transaction ended.

Transactions that are either implicitly or explicitly committed or rolled back will be
closed at the end of a Pyramid view. This is here for cleaning up caches so that
code after the view, exception views for example, will not be able to access
detached instances.

Example usage:

.. code-block:: python

   @util.db.on_transaction_end(session)
   def flush_cache():
       self._cache = {}
def on_transaction_end(session):
    '\n    Decorator for a function which should run after a top-level transaction ended.\n\n    Transactions that are either implicitly or explicitly committed or rolled back will be\n    closed at the end of a Pyramid view. This is here for cleaning up caches so that\n    code after the view, exception views for example, will not be able to access\n    detached instances.\n\n    Example usage:\n\n    .. code-block:: python\n\n       @util.db.on_transaction_end(session)\n       def flush_cache():\n           self._cache = {}\n\n    '

    def decorate(func):

        def _handler(_, transaction):
            if (transaction.parent is None):
                func()
        sqlalchemy.event.listen(session, 'after_transaction_end', _handler)
        return func
    return decorate