MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / __connect

Method __connect

lib/sqlalchemy/pool/base.py:886–912  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

884 self.dbapi_connection = None
885
886 def __connect(self) -> None:
887 pool = self.__pool
888
889 # ensure any existing connection is removed, so that if
890 # creator fails, this attribute stays None
891 self.dbapi_connection = None
892 try:
893 self.starttime = time.time()
894 self.dbapi_connection = connection = pool._invoke_creator(self)
895 pool.logger.debug("Created new connection %r", connection)
896 self.fresh = True
897 except BaseException as e:
898 with util.safe_reraise():
899 pool.logger.debug("Error on connect(): %s", e)
900 else:
901 # in SQLAlchemy 1.4 the first_connect event is not used by
902 # the engine, so this will usually not be set
903 if pool.dispatch.first_connect:
904 pool.dispatch.first_connect.for_modify(
905 pool.dispatch
906 ).exec_once_unless_exception(self.dbapi_connection, self)
907
908 # init of the dialect now takes place within the connect
909 # event, so ensure a mutex is used on the first run
910 pool.dispatch.connect.for_modify(
911 pool.dispatch
912 )._exec_w_sync_on_first_run(self.dbapi_connection, self)
913
914
915def _finalize_fairy(

Callers 2

__init__Method · 0.95
get_connectionMethod · 0.95

Calls 5

debugMethod · 0.80
timeMethod · 0.45
for_modifyMethod · 0.45

Tested by

no test coverage detected