MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / checkout

Method checkout

lib/sqlalchemy/pool/base.py:706–739  ·  view source on GitHub ↗
(cls, pool: Pool)

Source from the content-addressed store, hash-verified

704
705 @classmethod
706 def checkout(cls, pool: Pool) -> _ConnectionFairy:
707 if TYPE_CHECKING:
708 rec = cast(_ConnectionRecord, pool._do_get())
709 else:
710 rec = pool._do_get()
711
712 try:
713 dbapi_connection = rec.get_connection()
714 except BaseException as err:
715 with util.safe_reraise():
716 rec._checkin_failed(err, _fairy_was_created=False)
717
718 # not reached, for code linters only
719 raise
720
721 echo = pool._should_log_debug()
722 fairy = _ConnectionFairy(pool, dbapi_connection, rec, echo)
723
724 rec.fairy_ref = ref = weakref.ref(
725 fairy,
726 lambda ref: (
727 _finalize_fairy(
728 None, rec, pool, ref, echo, transaction_was_reset=False
729 )
730 if _finalize_fairy is not None
731 else None
732 ),
733 )
734 _strong_ref_connection_records[ref] = rec
735 if echo:
736 pool.logger.debug(
737 "Connection %r checked out from pool", dbapi_connection
738 )
739 return fairy
740
741 def _checkin_failed(
742 self, err: BaseException, _fairy_was_created: bool = True

Callers 1

_checkoutMethod · 0.45

Calls 8

_ConnectionFairyClass · 0.85
_finalize_fairyFunction · 0.85
get_connectionMethod · 0.80
_checkin_failedMethod · 0.80
_should_log_debugMethod · 0.80
debugMethod · 0.80
castFunction · 0.50
_do_getMethod · 0.45

Tested by

no test coverage detected