diff --git a/devlib/exception.py b/devlib/exception.py index 8bb6d2b..aa41eb4 100644 --- a/devlib/exception.py +++ b/devlib/exception.py @@ -14,9 +14,6 @@ # -from devlib.utils.misc import TimeoutError # NOQA pylint: disable=W0611 - - class DevlibError(Exception): """Base class for all Workload Automation exceptions.""" pass @@ -38,3 +35,17 @@ class HostError(DevlibError): """An error has occured on the host""" pass + +class TimeoutError(DevlibError): + """Raised when a subprocess command times out. This is basically a ``DevlibError``-derived version + of ``subprocess.CalledProcessError``, the thinking being that while a timeout could be due to + programming error (e.g. not setting long enough timers), it is often due to some failure in the + environment, and there fore should be classed as a "user error".""" + + def __init__(self, command, output): + super(TimeoutError, self).__init__('Timed out: {}'.format(command)) + self.command = command + self.output = output + + def __str__(self): + return '\n'.join([self.message, 'OUTPUT:', self.output or '']) diff --git a/devlib/utils/misc.py b/devlib/utils/misc.py index df27a1d..95c660d 100644 --- a/devlib/utils/misc.py +++ b/devlib/utils/misc.py @@ -36,6 +36,9 @@ from functools import partial import wrapt +from devlib.exception import TimeoutError + + # ABI --> architectures list ABI_MAP = { 'armeabi': ['armeabi', 'armv7', 'armv7l', 'armv7el', 'armv7lh'], @@ -120,22 +123,6 @@ def preexec_function(): check_output_logger = logging.getLogger('check_output') -# Defined here rather than in devlib.exceptions due to module load dependencies -class TimeoutError(Exception): - """Raised when a subprocess command times out. This is basically a ``WAError``-derived version - of ``subprocess.CalledProcessError``, the thinking being that while a timeout could be due to - programming error (e.g. not setting long enough timers), it is often due to some failure in the - environment, and there fore should be classed as a "user error".""" - - def __init__(self, command, output): - super(TimeoutError, self).__init__('Timed out: {}'.format(command)) - self.command = command - self.output = output - - def __str__(self): - return '\n'.join([self.message, 'OUTPUT:', self.output or '']) - - def check_output(command, timeout=None, ignore=None, inputtext=None, **kwargs): """This is a version of subprocess.check_output that adds a timeout parameter to kill the subprocess if it does not return within the specified time."""