Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les compléments
Voir le programme détaillé
Classe « Session »

Méthode sqlalchemy.orm.Session.invalidate

Signature de la méthode invalidate

def invalidate(self) -> 'None' 

Description

help(Session.invalidate)

Close this Session, using connection invalidation.

This is a variant of :meth:`.Session.close` that will additionally
ensure that the :meth:`_engine.Connection.invalidate`
method will be called on each :class:`_engine.Connection` object
that is currently in use for a transaction (typically there is only
one connection unless the :class:`_orm.Session` is used with
multiple engines).

This can be called when the database is known to be in a state where
the connections are no longer safe to be used.

Below illustrates a scenario when using `gevent
<https://www.gevent.org/>`_, which can produce ``Timeout`` exceptions
that may mean the underlying connection should be discarded::

    import gevent

    try:
        sess = Session()
        sess.add(User())
        sess.commit()
    except gevent.Timeout:
        sess.invalidate()
        raise
    except:
        sess.rollback()
        raise

The method additionally does everything that :meth:`_orm.Session.close`
does, including that all ORM objects are expunged.



Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les fondamentaux
Voir le programme détaillé