Commit ab7f71e9 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

fix a bug with errors handling

parent cdf6cf7a
......@@ -116,6 +116,7 @@ class Workflow(threading.Thread):
self.end_time = None
self.step = None
self.stderr = None
self.stderrfh = None
self.args = args
self.dynamic_component_present = False
self.__to_address = None
......@@ -428,6 +429,8 @@ class Workflow(threading.Thread):
return gr
def delete(self):
# first close the open files
self.stderrfh.close()
if self.get_status() in [self.STATUS_COMPLETED, self.STATUS_FAILED, self.STATUS_ABORTED]:
utils.robust_rmtree(self.directory)
......@@ -578,6 +581,7 @@ class Workflow(threading.Thread):
def __setstate__(self, state):
self.__dict__ = state.copy()
self.external_components = self._import_external_components()
self.stderr = self._set_stderr(True)
threading.Thread.__init__(self, name=self.name)
def __getstate__(self):
......@@ -590,6 +594,8 @@ class Workflow(threading.Thread):
del odict['_Thread__stderr']
if odict.has_key('external_components') :
del odict['external_components']
if odict.has_key('stderrfh') :
del odict['stderrfh']
return odict
def set_to_address(self, to_address):
......@@ -940,19 +946,19 @@ class Workflow(threading.Thread):
sys.stdout.write('{0:>10} {1:>10} {2}\n'.format('', 'COMMAND', node.command))
def _set_stderr(self):
if hasattr(self, "stderr") and self.stderr is not None:
os.rename( self.stderr, os.path.join(self.directory, str(time.time()) + self.STDERR_FILE_NAME + self.OLD_EXTENSION) )
def _set_stderr(self, keep_same_error_file=False):
# if it is specified to keep the same error file, keep with it
if not keep_same_error_file:
if hasattr(self, "stderr") and self.stderr is not None:
os.rename( self.stderr, os.path.join(self.directory, str(time.time()) + self.STDERR_FILE_NAME + self.OLD_EXTENSION) )
stderr = os.path.join(self.directory, self.STDERR_FILE_NAME)
logger = logging.getLogger( "wf." + str(self.id) )
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter( '## %(asctime)s :: %(message)s' )
file_handler = FileHandler(stderr, 'a')
file_handler.setLevel(logging.ERROR)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
# close file_handler to avoid nfs troubles
file_handler.close()
self.stderrfh = FileHandler(stderr, 'a')
self.stderrfh.setLevel(logging.ERROR)
self.stderrfh.setFormatter(formatter)
logger.addHandler(self.stderrfh)
return stderr
def _execute_weaver(self, engine_wrapper=None):
......
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