Close database connection on PGLoader object destruction, and on terminate() too

This commit is contained in:
dim 2008-05-21 07:44:30 +00:00
parent 32874eaede
commit 2d503ad0fa
2 changed files with 16 additions and 4 deletions

View File

@ -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)

View File

@ -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()