'Invalidate the underlying DBAPI connection associated with
this :class:`.Connection`.
The underlying DBAPI connection is literally closed (if
possible), and is discarded.  Its source connection pool will
typically lazily create a new connection to replace it.
Upon the next use (where "use" typically means using the
:meth:`.Connection.execute` method or similar),
this :class:`.Connection` will attempt to
procure a new DBAPI connection using the services of the
:class:`.Pool` as a source of connectivty (e.g. a "reconnection").
If a transaction was in progress (e.g. the
:meth:`.Connection.begin` method has been called) when
:meth:`.Connection.invalidate` method is called, at the DBAPI
level all state associated with this transaction is lost, as
the DBAPI connection is closed.  The :class:`.Connection`
will not allow a reconnection to proceed until the :class:`.Transaction`
object is ended, by calling the :meth:`.Transaction.rollback`
method; until that point, any attempt at continuing to use the
:class:`.Connection` will raise an
:class:`~sqlalchemy.exc.InvalidRequestError`.
This is to prevent applications from accidentally
continuing an ongoing transactional operations despite the
fact that the transaction has been lost due to an
invalidation.
The :meth:`.Connection.invalidate` method, just like auto-invalidation,
will at the connection pool level invoke the :meth:`.PoolEvents.invalidate`
event.
.. seealso::
:ref:`pool_connection_invalidation`'

def invalidate(self, exception=None):

    if self.invalidated:
        return
    if self.closed:
        raise exc.ResourceClosedError('This    Connection    is    closed')
    if self._connection_is_valid:
        self.__connection.invalidate(exception)
    del self.__connection
    self.__invalid = True
