Skip to content

Commit

Permalink
Crear el método: agregar código al método obtener Conexión (
Browse files Browse the repository at this point in the history
  • Loading branch information
angesc2022 committed Jun 25, 2023
1 parent 8f84ba4 commit 18acec8
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions Python/Semana 10/conexion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ class Conexion:
_HOST = '127.0.0.1'
_MIN_CON = 1
_MAX_CON = 5
_pool = None
_Pool = None


@classmethod
def obtenerConexion(cls):
pass

conexion = cls.obtenerPool().getconn()
log.debug(f'Conexion obtenida del pool: {conexion}')
return conexion


@classmethod
Expand All @@ -27,19 +29,28 @@ def obtenerCursor(cls):
def obtenerPool(cls):
if cls._pool is None:
try:
cls._pool = pool.SimpleConnectionPool(cls._MIN_CON,
cls._MAX_CON,
host=cls._HOST,
user=cls._USERNAME,
password=cls._PASSWORD,
port=cls._DB_PORT,
database=cls._DATABASE)
log.debug(f'creación del pool exitosa: {cls._pool}')
cls._pool = pool._simpleConnectionPool(cls._MIN_CON,
cls._MAX_CON,
host=cls._HOST,
User=cls._USERNAME,
password=cls._PASSWORD,
port=cls._BD_PORT,
database=cls._DATABASE)
log.debug(f'creacion del pool exitosa: {cls._pool}')
return cls._pool
except Exception as e:
log.error(f'Ocurrió un error al obtener el pool: {e}')
log.error(f'Ocurrio un error al obtener el pool: {e}')
sys.exit()
else:
return cls._pool



if __name__ == ' __main__ ':
pass
conexion1 = Conexion.obtenerConexion()
conexion2 = Conexion.obtenerConexion()
conexion3 = Conexion.obtenerConexion()
conexion4 = Conexion.obtenerConexion()
conexion5 = Conexion.obtenerConexion()


0 comments on commit 18acec8

Please sign in to comment.