diff --git a/rich/live.py b/rich/live.py index 6db5b605f9..2b2d0a8559 100644 --- a/rich/live.py +++ b/rich/live.py @@ -118,7 +118,15 @@ def start(self, refresh: bool = False) -> None: self._enable_redirect_io() self.console.push_render_hook(self) if refresh: - self.refresh() + try: + self.refresh() + except Exception: + # If refresh fails, we want to stop the redirection of sys.stderr, + # so the error stacktrace is properly displayed in the terminal. + # (or, if the code that calls Rich captures the exception and wants to display something, + # let this be displayed in the terminal). + self.stop() + raise if self.auto_refresh: self._refresh_thread = _RefreshThread(self, self.refresh_per_second) self._refresh_thread.start() @@ -210,7 +218,10 @@ def update(self, renderable: RenderableType, *, refresh: bool = False) -> None: def refresh(self) -> None: """Update the display of the Live Render.""" with self._lock: - self._live_render.set_renderable(self.renderable) + try: + self._live_render.set_renderable(self.renderable) + except Exception as e: + t = 2 if self.console.is_jupyter: # pragma: no cover try: from IPython.display import display