import mysql.connector import pydapper import logging import json import os import sys config_path = None def initPool(instancePath, connection_filename="connection_data_devel.json"): try: global config_path if(config_path == None): config_path = os.path.join(instancePath,f'../../../secure/{connection_filename}') #connection_data_devel.json'); print (config_path) if not os.path.exists(config_path): print ('cannot find ' + os.path.abspath(config_path)) print("instance path", instancePath) sys.exit(1) f = open(config_path); connection_data = json.load(f) conn_from_pool = mysql.connector.connect(**connection_data) commands = pydapper.using(conn_from_pool) data = commands.query("SELECT id from `user`") print("DB connection successful") conn_from_pool.close() except mysql.connector.PoolError as e: logging.error(f"Failed to create connection pool: {e}") print(e) except Exception as e: print(e) def getPoolConnection(): global config_path f = open(config_path); connection_data = json.load(f) return mysql.connector.connect(**connection_data)