Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle closed I/O error in spinner #2520

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions deeplake/util/spinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand All @@ -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():
Expand Down
Loading