raise AssertionError('lock process failed with returncode %s' \
% (proc.returncode,))
+ def _cancel(self):
+ if self._proc is not None:
+ self._proc.cancel()
+
def _wait(self):
if self.returncode is not None:
return self.returncode
-# Copyright 1999-2009 Gentoo Foundation
+# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from _emerge.SlotObject import SlotObject
return self.returncode
def cancel(self):
- self.cancelled = True
- self.wait()
+ if not self.cancelled:
+ self.cancelled = True
+ self._cancel()
+ self.wait()
+
+ def _cancel(self):
+ """
+ Subclasses should implement this, as a template method
+ to be called by AsynchronousTask.cancel().
+ """
+ pass
def addStartListener(self, f):
"""
def isAlive(self):
return self._current_task is not None
- def cancel(self):
- self.cancelled = True
+ def _cancel(self):
if self._current_task is not None:
if self._current_task is self._TASK_QUEUED:
self.returncode = 1
self._current_task = None
else:
self._current_task.cancel()
- AsynchronousTask.cancel(self)
def _poll(self):
"""
def isAlive(self):
return self._registered
- def cancel(self):
+ def _cancel(self):
if self.returncode is None:
self.returncode = 1
- self.cancelled = True
self._unregister()
- AbstractPollTask.cancel(self)
def _wait(self):
if self.returncode is not None:
def isAlive(self):
return self._registered
- def cancel(self):
+ def _cancel(self):
if self.returncode is None:
self.returncode = 1
- self.cancelled = True
- AbstractPollTask.cancel(self)
def _wait(self):
if self.returncode is not None:
self.wait()
return self.returncode
- def cancel(self):
+ def _cancel(self):
if self.isAlive():
try:
os.kill(self.pid, signal.SIGTERM)
except OSError as e:
if e.errno != errno.ESRCH:
raise
- del e
- AbstractPollTask.cancel(self)
def isAlive(self):
return self.pid is not None and \
def _start(self):
self._start_next_task()
- def cancel(self):
+ def _cancel(self):
self._task_queue.clear()
- CompositeTask.cancel(self)
def _start_next_task(self):
self._start_task(self._task_queue.popleft(),