Skip to content

Commit

Permalink
add reasons to stoppable interface and all stop implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Bengt committed Apr 23, 2014
1 parent 1797e63 commit e3d2056
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
7 changes: 4 additions & 3 deletions metaopt/invoker/dualthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions metaopt/invoker/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
4 changes: 2 additions & 2 deletions metaopt/invoker/pluggable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion metaopt/invoker/simple_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
3 changes: 2 additions & 1 deletion metaopt/invoker/singleprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions metaopt/invoker/util/status_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions metaopt/util/stoppable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BaseStoppable(object):
__metaclass__ = ABCMeta

@abstractmethod
def stop(self):
def stop(self, reason=None):
"""
Stops this object.
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit e3d2056

Please sign in to comment.