MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / close

Method close

lib/sqlalchemy/orm/session.py:2490–2529  ·  view source on GitHub ↗

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

2488 ).scalars()
2489
2490 def close(self) -> None:
2491 """Close out the transactional resources and ORM objects used by this
2492 :class:`_orm.Session`.
2493
2494 This expunges all ORM objects associated with this
2495 :class:`_orm.Session`, ends any transaction in progress and
2496 :term:`releases` any :class:`_engine.Connection` objects which this
2497 :class:`_orm.Session` itself has checked out from associated
2498 :class:`_engine.Engine` objects. The operation then leaves the
2499 :class:`_orm.Session` in a state which it may be used again.
2500
2501 .. tip::
2502
2503 In the default running mode the :meth:`_orm.Session.close`
2504 method **does not prevent the Session from being used again**.
2505 The :class:`_orm.Session` itself does not actually have a
2506 distinct "closed" state; it merely means
2507 the :class:`_orm.Session` will release all database connections
2508 and ORM objects.
2509
2510 Setting the parameter :paramref:`_orm.Session.close_resets_only`
2511 to ``False`` will instead make the ``close`` final, meaning that
2512 any further action on the session will be forbidden.
2513
2514 .. versionchanged:: 1.4 The :meth:`.Session.close` method does not
2515 immediately create a new :class:`.SessionTransaction` object;
2516 instead, the new :class:`.SessionTransaction` is created only if
2517 the :class:`.Session` is used again for a database operation.
2518
2519 .. seealso::
2520
2521 :ref:`session_closing` - detail on the semantics of
2522 :meth:`_orm.Session.close` and :meth:`_orm.Session.reset`.
2523
2524 :meth:`_orm.Session.reset` - a similar method that behaves like
2525 ``close()`` with the parameter
2526 :paramref:`_orm.Session.close_resets_only` set to ``True``.
2527
2528 """
2529 self._close_impl(invalidate=False)
2530
2531 def reset(self) -> None:
2532 """Close out the transactional resources and ORM objects used by this

Calls 1

_close_implMethod · 0.95