Handle more nicely connection errors - from python stacktrace to ERROR message

This commit is contained in:
dim 2008-02-15 09:53:06 +00:00
parent ba366190cc
commit 192da034c3
3 changed files with 19 additions and 16 deletions

View File

@ -465,7 +465,6 @@ def load_data():
threads = {}
current = 0
interrupted = False
got_errors = False
max_running = MAX_PARALLEL_SECTIONS
if max_running == -1:
@ -493,8 +492,6 @@ def load_data():
summary.pop(s)
except PGLoader_Error, e:
got_errors = True
if e == '':
log.error('[%s] Please correct previous errors' % s)
else:
@ -506,7 +503,6 @@ def load_data():
pass
except UnicodeDecodeError, e:
got_errors = True
log.error("can't open '%s' with given input encoding '%s'" \
% (filename, input_encoding))
@ -534,7 +530,7 @@ def load_data():
td = time.time() - begin
retcode = 0
if SUMMARY and not interrupted and not got_errors:
if SUMMARY and not interrupted:
try:
retcode = print_summary(None, sections, summary, td)
print

View File

@ -119,16 +119,22 @@ class db:
self.first_commit_time = self.last_commit_time
self.partial_coldef = None
if self.dbconn is not None:
self.log.debug('Debug: closing current connection')
self.dbconn.close()
try:
if self.dbconn is not None:
self.log.debug('Debug: closing current connection')
self.dbconn.close()
self.log.debug('Debug: connecting to dns %s', self.dsn)
self.log.debug('Debug: connecting to dns %s', self.dsn)
self.dbconn = psycopg.connect(self.dsn)
self.set_encoding()
self.set_datestyle()
self.set_lc_messages()
self.dbconn = psycopg.connect(self.dsn)
self.set_encoding()
self.set_datestyle()
self.set_lc_messages()
except psycopg.OperationalError, e:
# e.g. too many connections
self.log.error(e)
raise PGLoader_Error, "Can't connect to database"
def print_stats(self):
""" output some stats about recent activity """

View File

@ -134,8 +134,8 @@ class PGLoader(threading.Thread):
# Now reset database connection
if not DRY_RUN:
self.db.log = self.log
self.db.reset()
self.db.log = self.log
self.db.reset()
if not self.template and not DRY_RUN:
# check we have properly configured the copy separator
@ -1015,7 +1015,8 @@ class PGLoader(threading.Thread):
k = threads.keys()
for c in range(self.section_threads):
self.log.debug("locks[%d].acquire to set %s.done = True" % (c, k[c]))
self.log.debug("locks[%d].acquire to set %s.done = True" \
% (c, k[c]))
locks[c].acquire()
threads[k[c]].done = True