Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fy_spinner' into identify_slow_t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
nvoxland committed Aug 14, 2023
2 parents d8b8686 + c399404 commit ee7b6f1
Showing 1 changed file with 27 additions and 20 deletions.
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

Check warning on line 89 in deeplake/util/spinner.py

View check run for this annotation

Codecov / codecov/patch

deeplake/util/spinner.py#L76-L89

Added lines #L76 - L89 were not covered by tests

self._stop_event.wait(0.1)
except ValueError:

Check warning on line 92 in deeplake/util/spinner.py

View check run for this annotation

Codecov / codecov/patch

deeplake/util/spinner.py#L91-L92

Added lines #L91 - L92 were not covered by tests
# I/O operation on closed file
pass

Check warning on line 94 in deeplake/util/spinner.py

View check run for this annotation

Codecov / codecov/patch

deeplake/util/spinner.py#L94

Added line #L94 was not covered by tests

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:

Check warning on line 117 in deeplake/util/spinner.py

View check run for this annotation

Codecov / codecov/patch

deeplake/util/spinner.py#L112-L117

Added lines #L112 - L117 were not covered by tests
# I/O operation on closed file
pass

Check warning on line 119 in deeplake/util/spinner.py

View check run for this annotation

Codecov / codecov/patch

deeplake/util/spinner.py#L119

Added line #L119 was not covered by tests

def _clear_line(self):
if self.file.isatty():
Expand Down

0 comments on commit ee7b6f1

Please sign in to comment.