mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-04 18:36:12 +02:00
Close database connection on PGLoader object destruction, and on terminate() too
This commit is contained in:
parent
32874eaede
commit
2d503ad0fa
@ -89,9 +89,16 @@ class db:
|
||||
self.commits += 1
|
||||
self.commited_rows += self.running_commands
|
||||
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
""" close self.dbconn PostgreSQL connection """
|
||||
if self.dbconn is not None:
|
||||
self.log.debug('closing current connection')
|
||||
self.dbconn.close()
|
||||
|
||||
self.dbconn = None
|
||||
|
||||
def set_encoding(self):
|
||||
""" set connection encoding to self.client_encoding """
|
||||
# debug only cause reconnecting happens on every
|
||||
@ -195,10 +202,7 @@ ORDER BY attnum
|
||||
self.partial_coldef = None
|
||||
|
||||
try:
|
||||
if self.dbconn is not None:
|
||||
self.log.debug('Debug: closing current connection')
|
||||
self.dbconn.close()
|
||||
|
||||
self.close()
|
||||
self.log.debug('Debug: connecting to dns %s', self.dsn)
|
||||
|
||||
self.dbconn = psycopg.connect(self.dsn)
|
||||
|
||||
@ -152,6 +152,10 @@ class PGLoader(threading.Thread):
|
||||
|
||||
self.log.debug('%s init done' % name)
|
||||
|
||||
def __del__(self):
|
||||
""" PGLoader destructor, we close the db connection """
|
||||
self.db.close()
|
||||
|
||||
def _dbconnect(self, config):
|
||||
""" connects to database """
|
||||
section = 'pgsql'
|
||||
@ -841,6 +845,10 @@ class PGLoader(threading.Thread):
|
||||
def terminate(self):
|
||||
""" Announce it's over and free the concurrency control semaphore """
|
||||
|
||||
# force PostgreSQL connection closing, do not wait for garbage
|
||||
# collector
|
||||
self.db.close()
|
||||
|
||||
self.log.debug("releasing %s semaphore" % self.logname)
|
||||
self.sem.release()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user