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,6 +24,9 @@ class DbManager(object):
|
||||
cls.__connection = mariadb.connect(**cls.__con_param)
|
||||
print(f"DbManager Connection (INTERFACE ERROR): {e}..reconnecting...")
|
||||
except mariadb.Error as 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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
11
main.py
11
main.py
@@ -1,4 +1,4 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
# # !/home/linuxero/proj/tero/pyqcrm/.qtcreator/venv-3.13.0/bin/python3
|
||||
import sys
|
||||
import logging
|
||||
from PySide6.QtGui import QGuiApplication
|
||||
@@ -37,18 +37,19 @@ user = None
|
||||
|
||||
def initializeProgram():
|
||||
#print(f"In {__file__} file, initializeProgram()")
|
||||
global address_model, bad_config, business_model, user, business_type, contact_model
|
||||
global address_model, bad_config, business_model, user, business_type, contact_model, db_con
|
||||
if not bad_config:
|
||||
dbconf = config.getConfig()['database']
|
||||
DbManager(dbconf)
|
||||
bad_config = False
|
||||
if DbManager().getConnection():
|
||||
db_con = True
|
||||
user = UserManager()
|
||||
business_model = BusinessModel()
|
||||
address_model = AddressModel()
|
||||
business_type = BTypeModel()
|
||||
contact_model = ContactModel()
|
||||
|
||||
publishContext()
|
||||
bad_config = False
|
||||
|
||||
def publishContext():
|
||||
# print(f"In {__file__} file, publishContext()")
|
||||
@@ -79,8 +80,6 @@ if __name__ == "__main__":
|
||||
config.configurationReady.connect(initializeProgram)
|
||||
else:
|
||||
initializeProgram()
|
||||
if DbManager().getConnection():
|
||||
db_con = True
|
||||
|
||||
|
||||
engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}")
|
||||
|
||||
9
requirements.txt
Normal file
9
requirements.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PySide6
|
||||
platformdirs
|
||||
pycryptodome
|
||||
psutil
|
||||
toml
|
||||
mariadb
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user