Add connect_timout to DBManager connection and accelerate program start
on connection timeout
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
import mariadb
|
||||
|
||||
class DbManager(object):
|
||||
class DbManager():
|
||||
__connection = None
|
||||
__con_param = None
|
||||
__dbmanager = None
|
||||
@@ -14,7 +13,6 @@ class DbManager(object):
|
||||
|
||||
return cls.__dbmanager
|
||||
|
||||
|
||||
def getConnection(cls):
|
||||
#print(f"DB Manager: {cls.__dbmanager}")
|
||||
#print(f"DB Connection: {cls.__connection}")
|
||||
@@ -26,7 +24,10 @@ class DbManager(object):
|
||||
cls.__connection = mariadb.connect(**cls.__con_param)
|
||||
print(f"DbManager Connection (INTERFACE ERROR): {e}..reconnecting...")
|
||||
except mariadb.Error as e:
|
||||
print(f"File: {__file__}\n Database connection error: {e}")
|
||||
if '(110)' in str(e):
|
||||
print(f"File: {__file__}\n Database connection timed out (Check connection parameters or server): {e}")
|
||||
else:
|
||||
print(f"File: {__file__}\n Database connection error: {e}")
|
||||
cls.__connection = None
|
||||
|
||||
return cls.__connection
|
||||
@@ -34,7 +35,7 @@ class DbManager(object):
|
||||
def __initializeConfig(cls, dbconf):
|
||||
cls.__con_param = { 'user': dbconf['DB_USER'], 'password': dbconf['DB_PASS'],
|
||||
'port': int (dbconf['DB_PORT']), 'host': dbconf['DB_HOST'],
|
||||
'database': dbconf['DB_NAME']
|
||||
'database': dbconf['DB_NAME'], 'connect_timeout': 5
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user