"""
# Standard modules
-# import errno
+import errno
-__version__ = '0.3.2'
+__version__ = '0.4.1'
# =============================================================================
class PpError(Exception):
msg = "Function {func}() has to be overridden in class {cls!r}."
return msg.format(func=self.function_name, cls=self.class_name)
+# =============================================================================
+class IoTimeoutError(PpError, IOError):
+ """
+ Special error class indicating a timout error on a read/write operation
+ """
+
+ # -------------------------------------------------------------------------
+ def __init__(self, strerror, timeout, filename=None):
+ """
+ Constructor.
+
+ @param strerror: the error message about the operation
+ @type strerror: str
+ @param timeout: the timout in seconds leading to the error
+ @type timeout: float
+ @param filename: the filename leading to the error
+ @type filename: str
+
+ """
+
+ t_o = None
+ try:
+ t_o = float(timeout)
+ except ValueError:
+ pass
+ self.timeout = t_o
+
+ if t_o is not None:
+ strerror += " (timeout after {:0.1f} secs)".format(t_o)
+
+ if filename is None:
+ super(IoTimeoutError, self).__init__(errno.ETIMEDOUT, strerror)
+ else:
+ super(IoTimeoutError, self).__init__(
+ errno.ETIMEDOUT, strerror, filename)
+
+# =============================================================================
+class ReadTimeoutError(IoTimeoutError):
+ """
+ Special error class indicating a timout error on reading of a file.
+ """
+
+ # -------------------------------------------------------------------------
+ def __init__(self, timeout, filename):
+ """
+ Constructor.
+
+ @param timeout: the timout in seconds leading to the error
+ @type timeout: float
+ @param filename: the filename leading to the error
+ @type filename: str
+
+ """
+
+ strerror = "Timeout error on reading"
+ super(ReadTimeoutError, self).__init__(strerror, timeout, filename)
+
+
+# =============================================================================
+class WriteTimeoutError(IoTimeoutError):
+ """
+ Special error class indicating a timout error on a writing into a file.
+ """
+
+ # -------------------------------------------------------------------------
+ def __init__(self, timeout, filename):
+ """
+ Constructor.
+
+ @param timeout: the timout in seconds leading to the error
+ @type timeout: float
+ @param filename: the filename leading to the error
+ @type filename: str
+
+ """
+
+ strerror = "Timeout error on writing"
+ super(WriteTimeoutError, self).__init__(strerror, timeout, filename)
+
+# =============================================================================
+class CouldntOccupyLockfileError(PpError):
+ """
+ Special error class indicating, that a lockfile couldn't coccupied
+ after a defined time.
+ """
+
+ # -----------------------------------------------------
+ def __init__(self, lockfile, duration, tries):
+ """
+ Constructor.
+
+ @param lockfile: the lockfile, which could't be occupied.
+ @type lockfile: str
+ @param duration: The duration in seconds, which has lead to this situation
+ @type duration: float
+ @param tries: the number of tries creating the lockfile
+ @type tries: int
+
+ """
+
+ self.lockfile = str(lockfile)
+ self.duration = float(duration)
+ self.tries = int(tries)
+
+ # -----------------------------------------------------
+ def __str__(self):
+
+ return "Couldn't occupy lockfile {!r} in {:0.1f} seconds with {} tries.".format(
+ self.lockfile, self.duration, self.tries)
+
# =============================================================================