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

Method checkout

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

Source from the content-addressed store, hash-verified

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

Callers 1

_checkoutMethod · 0.45

Calls 8

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

Tested by

no test coverage detected