Skip to content

Commit

Permalink
Remove the _error_handlers list attribute from BaseRestartWorkChain
Browse files Browse the repository at this point in the history
Because it was defined as a class attribute for the BaseRestartWorkChain
each time the register_error_handler decorator was used, the method was
appended to the exact same list, regardless of the workchain class to
which it was supposed to be applied.
  • Loading branch information
sphuber committed May 7, 2018
1 parent d945a43 commit 5ffee13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions aiida_quantumespresso/common/workchain/base/restart.py
Expand Up @@ -52,7 +52,6 @@ class BaseRestartWorkChain(WorkChain):
before the next calculation will be run with those inputs.
"""
_verbose = False
_error_handlers = []
_calculation_class = None
_error_handler_entry_point = None
_expected_calculation_states = [calc_states.FINISHED, calc_states.FAILED, calc_states.SUBMISSIONFAILED]
Expand Down Expand Up @@ -148,7 +147,7 @@ def inspect_calculation(self):

# Abort: exceeded maximum number of retries
elif self.ctx.iteration >= self.inputs.max_iterations.value:
self.abort_nowait('reached the maximumm number of iterations {}\nlast ran {}<{}>'
self.abort_nowait('reached the maximumm number of iterations {}: last ran {}<{}>'
.format(self.inputs.max_iterations.value, self._calculation_class.__name__, calculation.pk))

# Abort: unexpected state of last calculation
Expand Down
7 changes: 7 additions & 0 deletions aiida_quantumespresso/common/workchain/utils.py
Expand Up @@ -56,12 +56,19 @@ def register_error_handler(cls, priority):
during the handling of a failed calculation. Higher priorities will be handled first
"""
def error_handler_decorator(handler):

@wraps(handler)
def error_handler(self, calculation):
if hasattr(cls, '_verbose') and cls._verbose:
self.report('({}){}'.format(priority, handler.__name__))
return handler(self, calculation)

setattr(cls, handler.__name__, error_handler)

if not hasattr(cls, '_error_handlers'):
cls._error_handlers = []
cls._error_handlers.append(ErrorHandler(priority, error_handler))

return error_handler

return error_handler_decorator

0 comments on commit 5ffee13

Please sign in to comment.