From c399404ca72f84de7e8125a2ee02d6915c1f0e3e Mon Sep 17 00:00:00 2001 From: FayazRahman Date: Sun, 6 Aug 2023 17:13:16 +0530 Subject: [PATCH] error handling --- deeplake/util/spinner.py | 47 +++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/deeplake/util/spinner.py b/deeplake/util/spinner.py index 82a340f648..1f70eec90b 100644 --- a/deeplake/util/spinner.py +++ b/deeplake/util/spinner.py @@ -55,7 +55,6 @@ def run_spinner(spinner): yield finally: if spinner_started: - spinner._show_cursor() spinner.stop() sys.stdout = save_stdout sys.stderr = save_stderr @@ -74,21 +73,25 @@ def __init__(self, *args, **kwargs): self.file = sys.stderr def run(self): - time.sleep(deeplake.constants.SPINNER_START_DELAY) - frames = cycle("/-\\|") - if not self._hide_event.is_set(): - self._hide_cursor() - while not self._stop_event.is_set(): - if self._hide_event.is_set(): - time.sleep(0.1) - continue - with self._stderr_lock: - self._clear_line() - self.file.write(next(frames)) - self.file.flush() - self._cur_line_len = 1 - - self._stop_event.wait(0.1) + try: + time.sleep(deeplake.constants.SPINNER_START_DELAY) + frames = cycle("/-\\|") + if not self._hide_event.is_set(): + self._hide_cursor() + while not self._stop_event.is_set(): + if self._hide_event.is_set(): + time.sleep(0.1) + continue + with self._stderr_lock: + self._clear_line() + self.file.write(next(frames)) + self.file.flush() + self._cur_line_len = 1 + + self._stop_event.wait(0.1) + except ValueError: + # I/O operation on closed file + pass def hide(self): if not self._hide_event.is_set(): @@ -106,10 +109,14 @@ def show(self): self._hide_cursor() def stop(self): - self._stop_event.set() - if not self._hide_event.is_set(): - self._clear_line() - self._show_cursor() + try: + self._stop_event.set() + if not self._hide_event.is_set(): + self._clear_line() + self._show_cursor() + except ValueError: + # I/O operation on closed file + pass def _clear_line(self): if self.file.isatty():