r"""Close out the transactional resources and ORM objects used by this :class:`_orm.Session`. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_orm.scoping.scoped_session` class. This expunges all ORM o
(self)
| 485 | return self._proxied.begin_nested() |
| 486 | |
| 487 | def close(self) -> None: |
| 488 | r"""Close out the transactional resources and ORM objects used by this |
| 489 | :class:`_orm.Session`. |
| 490 | |
| 491 | .. container:: class_bases |
| 492 | |
| 493 | Proxied for the :class:`_orm.Session` class on |
| 494 | behalf of the :class:`_orm.scoping.scoped_session` class. |
| 495 | |
| 496 | This expunges all ORM objects associated with this |
| 497 | :class:`_orm.Session`, ends any transaction in progress and |
| 498 | :term:`releases` any :class:`_engine.Connection` objects which this |
| 499 | :class:`_orm.Session` itself has checked out from associated |
| 500 | :class:`_engine.Engine` objects. The operation then leaves the |
| 501 | :class:`_orm.Session` in a state which it may be used again. |
| 502 | |
| 503 | .. tip:: |
| 504 | |
| 505 | In the default running mode the :meth:`_orm.Session.close` |
| 506 | method **does not prevent the Session from being used again**. |
| 507 | The :class:`_orm.Session` itself does not actually have a |
| 508 | distinct "closed" state; it merely means |
| 509 | the :class:`_orm.Session` will release all database connections |
| 510 | and ORM objects. |
| 511 | |
| 512 | Setting the parameter :paramref:`_orm.Session.close_resets_only` |
| 513 | to ``False`` will instead make the ``close`` final, meaning that |
| 514 | any further action on the session will be forbidden. |
| 515 | |
| 516 | .. versionchanged:: 1.4 The :meth:`.Session.close` method does not |
| 517 | immediately create a new :class:`.SessionTransaction` object; |
| 518 | instead, the new :class:`.SessionTransaction` is created only if |
| 519 | the :class:`.Session` is used again for a database operation. |
| 520 | |
| 521 | .. seealso:: |
| 522 | |
| 523 | :ref:`session_closing` - detail on the semantics of |
| 524 | :meth:`_orm.Session.close` and :meth:`_orm.Session.reset`. |
| 525 | |
| 526 | :meth:`_orm.Session.reset` - a similar method that behaves like |
| 527 | ``close()`` with the parameter |
| 528 | :paramref:`_orm.Session.close_resets_only` set to ``True``. |
| 529 | |
| 530 | |
| 531 | """ # noqa: E501 |
| 532 | |
| 533 | return self._proxied.close() |
| 534 | |
| 535 | def reset(self) -> None: |
| 536 | r"""Close out the transactional resources and ORM objects used by this |