提交 a69008c4 编写于 作者: A Adam Lee 提交者: Adam Lee

Fix gpload exiting before cleaning up

gpload.cleanupSql() in the `finally` block may throw a `SystemExit`
exception, which will not be caught by `except Exception:` and exit
before cleaning up others like gpfdist processes.

This commit catches `SystemExit`, and do the stop_gpfdists() before
cleanupSql() to avoid this situation.
Signed-off-by: NAdam Lee <ali@pivotal.io>
Signed-off-by: NXiaoran Wang <xiwang@pivotal.io>
上级 cd50e9b4
......@@ -2696,6 +2696,26 @@ class gpload:
self.db.query("COMMIT")
def stop_gpfdists(self):
if self.subprocesses:
self.log(self.LOG, 'killing gpfdist')
for a in self.subprocesses:
try:
if platform.system() in ['Windows', 'Microsoft']:
# win32 API is better but hard for us
# to install, so we use the crude method
subprocess.Popen("taskkill /F /T /PID %i" % a.pid,
shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
else:
os.kill(a.pid, signal.SIGTERM)
except OSError:
pass
for t in self.threads:
t.join()
def run2(self):
self.log(self.DEBUG, 'config ' + str(self.config))
start = time.time()
......@@ -2732,6 +2752,8 @@ class gpload:
self.log(self.ERROR, "unexpected error -- backtrace " +
"written to log file")
finally:
self.stop_gpfdists()
if self.cleanupSql:
self.log(self.LOG, 'removing temporary data')
self.setup_connection()
......@@ -2739,27 +2761,10 @@ class gpload:
try:
self.log(self.DEBUG, a)
self.db.query(a.encode('utf-8'))
except Exception:
except (Exception, SystemExit):
traceback.print_exc(file=self.logfile)
self.logfile.flush()
traceback.print_exc()
if self.subprocesses:
self.log(self.LOG, 'killing gpfdist')
for a in self.subprocesses:
try:
if platform.system() in ['Windows', 'Microsoft']:
# win32 API is better but hard for us
# to install, so we use the crude method
subprocess.Popen("taskkill /F /T /PID %i" % a.pid,
shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
else:
os.kill(a.pid, signal.SIGTERM)
except OSError:
pass
for t in self.threads:
t.join()
if self.db != None:
self.db.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册