diff --git a/metaopt/invoker/dualthread.py b/metaopt/invoker/dualthread.py index 1747743..58d1424 100644 --- a/metaopt/invoker/dualthread.py +++ b/metaopt/invoker/dualthread.py @@ -105,15 +105,16 @@ def wait(self): @stoppable_method @stopping_method - def stop(self): + def stop(self, reason=None): """Stops this invoker.""" with self.lock: self.aborted = True - self.stop_task(self.current_task) + self.stop_task(self.current_task, reason=reason) - def stop_task(self, task): + def stop_task(self, task, reason=None): """Stops the given task.""" + del reason # TODO with self.lock: if self.call_handle is not task: return diff --git a/metaopt/invoker/multiprocess.py b/metaopt/invoker/multiprocess.py index acab453..c1d780a 100644 --- a/metaopt/invoker/multiprocess.py +++ b/metaopt/invoker/multiprocess.py @@ -228,7 +228,7 @@ def stop_call(self, call_id, reason): @stoppable_method @stopping_method - def stop(self): + def stop(self, reason=None): """ Terminates all worker processes for immediate shutdown. @@ -242,6 +242,6 @@ def stop(self): outcome = self._status_db.wait_for_one_outcome() self._handle_outcome(outcome=outcome) - self._status_db.stop() + self._status_db.stop(reason=reason) self._manager.shutdown() diff --git a/metaopt/invoker/pluggable.py b/metaopt/invoker/pluggable.py index 5a624af..1217c10 100644 --- a/metaopt/invoker/pluggable.py +++ b/metaopt/invoker/pluggable.py @@ -127,6 +127,6 @@ def wait(self): @stoppable_method @stopping_method - def stop(self): + def stop(self, reason=None): """Stops this invoker.""" - self._invoker.stop() + self._invoker.stop(reason=reason) diff --git a/metaopt/invoker/simple_multiprocess.py b/metaopt/invoker/simple_multiprocess.py index 1451bb3..2b818e7 100644 --- a/metaopt/invoker/simple_multiprocess.py +++ b/metaopt/invoker/simple_multiprocess.py @@ -117,7 +117,8 @@ def call_on_result(self, result): actual_result = result.actual_result caller.on_result(actual_result, worker_fargs, **worker_kwargs) - def stop(self): + def stop(self, reason=None): + del reason # TODO self.result_queue.put(None) diff --git a/metaopt/invoker/singleprocess.py b/metaopt/invoker/singleprocess.py index 6596e13..d313721 100644 --- a/metaopt/invoker/singleprocess.py +++ b/metaopt/invoker/singleprocess.py @@ -41,6 +41,7 @@ def wait(self): @stoppable_method @stopping_method - def stop(self): + def stop(self, reason=None): """Stops this invoker.""" + del reason # TODO raise NotImplementedError() diff --git a/metaopt/invoker/util/status_db.py b/metaopt/invoker/util/status_db.py index 65d9d42..22fd306 100644 --- a/metaopt/invoker/util/status_db.py +++ b/metaopt/invoker/util/status_db.py @@ -199,7 +199,7 @@ def _empty_queue_outcome(self): self._handle_outcome(outcome) @stopping_method - def stop(self): + def stop(self, reason=None): """""" self._empty_queue_task() assert self._queue_task.empty() @@ -222,7 +222,7 @@ def stop(self): for task in self._call_status_dict.values(): if not isinstance(task, Task): continue - release = Release(worker_id=None, call=task.call, value='release') + release = Release(worker_id=None, call=task.call, value=reason) self._queue_outcome.put(release) while not self._queue_outcome.empty(): diff --git a/metaopt/util/stoppable.py b/metaopt/util/stoppable.py index c1a71af..9b9f8b5 100644 --- a/metaopt/util/stoppable.py +++ b/metaopt/util/stoppable.py @@ -12,7 +12,7 @@ class BaseStoppable(object): __metaclass__ = ABCMeta @abstractmethod - def stop(self): + def stop(self, reason=None): """ Stops this object. @@ -81,7 +81,7 @@ def __init__(self): @stoppable_method @stopping_method - def stop(self): + def stop(self, reason=None): """"Stops this object.""" pass # implementations may overwrite this method or check for .stopped