Commit a28caef0 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added shutdown method to process controller. Fixed test_cli.py.

parent 880f9ef6
......@@ -148,7 +148,7 @@ def get_gms_argparser():
# metavar=tuple("[run processor, write output, delete output]".split(' ')), default=[1, 1, 1]),
gop_p('-DH', '--db_host', nargs='?', type=str,
default=options_default["global_opts"]["db_host"],
default='localhost', # hardcoded here because default json is read from database and host must be available
help='host name of the server that runs the postgreSQL database')
gop_p('-DOO', '--delete_old_output', nargs='?', type=bool,
......
......@@ -137,6 +137,7 @@ class L1A_object(GMS_object):
#####################################
# validate number of expected files #
#####################################
if re.search('ETM+', self.sensor) and self.acq_datetime > datetime.datetime(year=2003, month=5, day=31):
expected_files_count = 2 * len(full_LayerBandsAssignment)
else:
......@@ -149,6 +150,7 @@ class L1A_object(GMS_object):
###############################
# get paths of files to stack #
###############################
# NOTE: image_files is a SORTED list of image filenames; self.LayerBandsAssignment may be sorted by CWL
filtered_files = []
for bN in self.LayerBandsAssignment: # unsorted, e.g., ['1', '2', '3', '4', '5', '9', '6', '7']
......@@ -161,6 +163,7 @@ class L1A_object(GMS_object):
#########################
# read the raster data #
#########################
rasObj = GEOP.GEOPROCESSING(paths_files2stack[0], self.logger)
# in case a subset is to be read: prepare rasObj instance to read a subset
......
......@@ -969,8 +969,8 @@ class AtmCorr(object):
inObj.ac_errors = ac_errors # setter generates a GeoArray with the same bandnames like inObj.arr
# TODO how to handle nans?
elif not CFG.ac_estimate_accuracy:
self.logger.warning("Atmospheric correction did not provide a 'data_errors' array because "
"'ac_estimate_accuracy' was set to False in the job configuration.")
self.logger.info("Atmospheric correction did not provide a 'data_errors' array because "
"'ac_estimate_accuracy' was set to False in the job configuration.")
else:
self.logger.warning("Atmospheric correction did not provide a 'data_errors' array. Maybe due to "
"missing SNR model? GMS_object.ac_errors kept None.")
......@@ -1043,8 +1043,8 @@ class AtmCorr(object):
self.logger.warning('Cloud mask confidence array has not been appended to one of the AC inputs because '
'there was no input GMS object with the same dimensions.')
elif not CFG.ac_estimate_accuracy:
self.logger.warning("Cloud mask confidence array is not appended to AC outputs because "
"'ac_estimate_accuracy' was set to False in the job configuration.")
self.logger.info("Cloud mask confidence array is not appended to AC outputs because "
"'ac_estimate_accuracy' was set to False in the job configuration.")
else:
self.logger.warning("Atmospheric correction did not provide a 'mask_confidence_array' array for "
"attribute 'mask_clouds. GMS_object.mask_clouds_confidence kept None.")
......@@ -806,11 +806,10 @@ class GMSValidator(Validator):
def get_options(target, validation=True):
"""
return dictionary will all options
:param validation: True / False, whether to validate options read from files ot not
:param target: if path to file, then json is used to load, otherwise the default template
is used
"""Return dictionary with all options.
:param validation: True / False, whether to validate options read from files or not
:param target: if path to file, then json is used to load, otherwise the default template is used
:return: dictionary with options
"""
......@@ -823,4 +822,4 @@ def get_options(target, validation=True):
return options
else:
raise FileNotFoundError("target: %s is not a valid file path" % target)
raise FileNotFoundError("Options file not found at file path %s." % target)
......@@ -36,11 +36,11 @@ def L1A_map(dataset_dict): # map (scene-wise parallelization)
L1A_obj.calc_mean_VAA()
L1A_obj.calc_orbit_overpassParams() # requires corner positions
L1A_obj.apply_nodata_mask_to_ObjAttr('mask_clouds', 0)
if CFG.exec_L1AP[1]:
L1A_obj.to_ENVI()
L1A_obj.delete_tempFiles()
else:
L1A_obj.delete_tempFiles()
L1A_obj.delete_tempFiles()
return L1A_obj
......
......@@ -396,7 +396,7 @@ class process_controller(object):
self.profiler.stop()
print(self.profiler.output_text(unicode=True, color=True))
shutdown_loggers()
self.shutdown()
except Exception: # noqa E722 # bare except
if self.config.profiling:
......@@ -408,10 +408,10 @@ class process_controller(object):
if not self.config.disable_exception_handler:
self.logger.error('Execution failed with an error:', exc_info=True)
shutdown_loggers()
self.shutdown()
else:
self.logger.error('Execution failed with an error:')
shutdown_loggers()
self.shutdown()
raise
def run_all_processors(self, custom_data_list=None):
......@@ -477,7 +477,7 @@ class process_controller(object):
self.profiler.stop()
print(self.profiler.output_text(unicode=True, color=True))
shutdown_loggers()
self.shutdown()
except Exception: # noqa E722 # bare except
if self.config.profiling:
......@@ -489,10 +489,10 @@ class process_controller(object):
if not self.config.disable_exception_handler:
self.logger.error('Execution failed with an error:', exc_info=True)
shutdown_loggers()
self.shutdown()
else:
self.logger.error('Execution failed with an error:')
shutdown_loggers()
self.shutdown()
raise
def stop(self, signum, frame):
......@@ -501,7 +501,14 @@ class process_controller(object):
self.config.status = 'canceled'
self.update_DB_job_record()
self.shutdown()
self.logger.warning('Process controller stopped by user.')
raise KeyboardInterrupt # terminate execution and show traceback
def shutdown(self):
"""Shutdown the process controller instance (loggers, remove temporary directories, ...)."""
del self.logger
shutdown_loggers()
......@@ -510,8 +517,6 @@ class process_controller(object):
self.logger.warning('Deleting temporary directory %s.' % tempdir)
shutil.rmtree(tempdir)
raise KeyboardInterrupt # terminate execution and show traceback
def benchmark(self):
"""
Run a benchmark.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment