Include error message with error status
This commit is contained in:
@@ -70,7 +70,10 @@ class FileTransferer(threading.Thread, metaclass=abc.ABCMeta):
|
||||
self.queue = queue.PriorityQueue(maxsize=100) # type: queue.PriorityQueue[QueueItem]
|
||||
self.done = threading.Event()
|
||||
self._abort = threading.Event() # Indicates user-requested abort
|
||||
self._error = threading.Event() # Indicates abort due to some error
|
||||
|
||||
self.__error_mutex = threading.Lock()
|
||||
self.__error = threading.Event() # Indicates abort due to some error
|
||||
self.__error_message = ''
|
||||
|
||||
# Instantiate a dummy progress callback so that we can call it
|
||||
# without checking for None all the time.
|
||||
@@ -86,7 +89,7 @@ class FileTransferer(threading.Thread, metaclass=abc.ABCMeta):
|
||||
"""Queue a copy action from 'src' to 'dst'."""
|
||||
assert not self.done.is_set(), 'Queueing not allowed after done_and_join() was called'
|
||||
assert not self._abort.is_set(), 'Queueing not allowed after abort_and_join() was called'
|
||||
if self._error.is_set():
|
||||
if self.__error.is_set():
|
||||
return
|
||||
self.queue.put((src, dst, Action.COPY))
|
||||
self.total_queued_bytes += src.stat().st_size
|
||||
@@ -95,7 +98,7 @@ class FileTransferer(threading.Thread, metaclass=abc.ABCMeta):
|
||||
"""Queue a move action from 'src' to 'dst'."""
|
||||
assert not self.done.is_set(), 'Queueing not allowed after done_and_join() was called'
|
||||
assert not self._abort.is_set(), 'Queueing not allowed after abort_and_join() was called'
|
||||
if self._error.is_set():
|
||||
if self.__error.is_set():
|
||||
return
|
||||
self.queue.put((src, dst, Action.MOVE))
|
||||
self.total_queued_bytes += src.stat().st_size
|
||||
@@ -156,7 +159,7 @@ class FileTransferer(threading.Thread, metaclass=abc.ABCMeta):
|
||||
"""Generator, yield queued items until the work is done."""
|
||||
|
||||
while True:
|
||||
if self._abort.is_set() or self._error.is_set():
|
||||
if self._abort.is_set() or self.__error.is_set():
|
||||
return
|
||||
|
||||
try:
|
||||
@@ -197,4 +200,22 @@ class FileTransferer(threading.Thread, metaclass=abc.ABCMeta):
|
||||
|
||||
@property
|
||||
def has_error(self) -> bool:
|
||||
return self._error.is_set()
|
||||
return self.__error.is_set()
|
||||
|
||||
def error_set(self, message: str):
|
||||
"""Indicate an error occurred, and provide a message."""
|
||||
|
||||
with self.__error_mutex:
|
||||
# Avoid overwriting previous error messages.
|
||||
if self.__error.is_set():
|
||||
return
|
||||
|
||||
self.__error.set()
|
||||
self.__error_message = message
|
||||
|
||||
def error_message(self) -> str:
|
||||
"""Retrieve the error messsage, or an empty string if no error occurred."""
|
||||
with self.__error_mutex:
|
||||
if not self.__error.is_set():
|
||||
return ''
|
||||
return self.__error_message
|
||||
|
||||
Reference in New Issue
Block a user