MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / close

Method close

lib/sqlalchemy/orm/session.py:2584–2623  ·  lib/sqlalchemy/orm/session.py::Session.close

Close out the transactional resources and ORM objects used by this :class:`_orm.Session`. This expunges all ORM objects associated with this :class:`_orm.Session`, ends any transaction in progress and :term:`releases` any :class:`_engine.Connection` objects which thi

(self)

Source from the content-addressed store, hash-verified

2582 ).scalars()
2583
2584 def close(self) -> None:
2585 class="st">"""Close out the transactional resources and ORM objects used by this
2586 :class:`_orm.Session`.
2587
2588 This expunges all ORM objects associated with this
2589 :class:`_orm.Session`, ends any transaction in progress and
2590 :term:`releases` any :class:`_engine.Connection` objects which this
2591 :class:`_orm.Session` itself has checked out from associated
2592 :class:`_engine.Engine` objects. The operation then leaves the
2593 :class:`_orm.Session` in a state which it may be used again.
2594
2595 .. tip::
2596
2597 In the default running mode the :meth:`_orm.Session.close`
2598 method **does not prevent the Session from being used again**.
2599 The :class:`_orm.Session` itself does not actually have a
2600 distinct class="st">"closed" state; it merely means
2601 the :class:`_orm.Session` will release all database connections
2602 and ORM objects.
2603
2604 Setting the parameter :paramref:`_orm.Session.close_resets_only`
2605 to ``False`` will instead make the ``close`` final, meaning that
2606 any further action on the session will be forbidden.
2607
2608 .. versionchanged:: 1.4 The :meth:`.Session.close` method does not
2609 immediately create a new :class:`.SessionTransaction` object;
2610 instead, the new :class:`.SessionTransaction` is created only if
2611 the :class:`.Session` is used again for a database operation.
2612
2613 .. seealso::
2614
2615 :ref:`session_closing` - detail on the semantics of
2616 :meth:`_orm.Session.close` and :meth:`_orm.Session.reset`.
2617
2618 :meth:`_orm.Session.reset` - a similar method that behaves like
2619 ``close()`` with the parameter
2620 :paramref:`_orm.Session.close_resets_only` set to ``True``.
2621
2622 class="st">"""
2623 self._close_impl(invalidate=False)
2624
2625 def reset(self) -> None:
2626 class="st">"""Close out the transactional resources and ORM objects used by this

Calls 1

_close_implMethod · 0.95