mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-30 16:14:21 +02:00
return db object to keep it from going out of scope
This commit is contained in:
+11
-4
@@ -138,12 +138,17 @@ def connectDB():
|
|||||||
db_inst = MySQLdb.connect(host=db_server, port=db_port, user=db_username, passwd=db_password, db=db_dbname)
|
db_inst = MySQLdb.connect(host=db_server, port=db_port, user=db_username, passwd=db_password, db=db_dbname)
|
||||||
db_inst.autocommit(True)
|
db_inst.autocommit(True)
|
||||||
cursor_inst = db_inst.cursor()
|
cursor_inst = db_inst.cursor()
|
||||||
return cursor_inst
|
ret = namedtuple('db_connection', ['db', 'cursor'])
|
||||||
|
ret.db = db_inst
|
||||||
|
ret.cursor = cursor_inst
|
||||||
|
return ret
|
||||||
except:
|
except:
|
||||||
log.critical("ERROR: Could not connect to MySQL database!")
|
log.critical("ERROR: Could not connect to MySQL database!")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
cursor = connectDB()
|
db_connection = connectDB()
|
||||||
|
db = db_connection.db
|
||||||
|
cursor = db_connection.cursor
|
||||||
|
|
||||||
def poll_worker(device_id, action):
|
def poll_worker(device_id, action):
|
||||||
try:
|
try:
|
||||||
@@ -180,9 +185,11 @@ def getLock(lock, cursor=cursor):
|
|||||||
|
|
||||||
thread_cursors = []
|
thread_cursors = []
|
||||||
for i in range(0, amount_of_workers):
|
for i in range(0, amount_of_workers):
|
||||||
thread_cursors.append(namedtuple('Cursor{}'.format(i), ['in_use', 'cursor']))
|
thread_cursors.append(namedtuple('Cursor{}'.format(i), ['in_use', 'cursor', 'db']))
|
||||||
thread_cursors[i].in_use = False
|
thread_cursors[i].in_use = False
|
||||||
thread_cursors[i].cursor = connectDB
|
thread_db_connection = connectDB()
|
||||||
|
thread_cursors[i].cursor = thread_db_connection.cursor
|
||||||
|
thread_cursors[i].db = thread_db_connection.db
|
||||||
|
|
||||||
|
|
||||||
def getThreadLock(lock):
|
def getThreadLock(lock):
|
||||||
|
|||||||
Reference in New Issue
Block a user