Skip to content

Commit

Permalink
Merge pull request #2305 from Textualize/fix-invalid-markup-crash
Browse files Browse the repository at this point in the history
[live] Restore `sys.stderr` when an exception happens during a refresh
  • Loading branch information
willmcgugan committed May 27, 2022
2 parents aa7926c + cf99a8d commit 5ccf4ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Allow exceptions that are raised while a Live is rendered to be displayed and/or processed https://github.com/Textualize/rich/pull/2305

## [12.4.4] - 2022-05-24

### Changed
Expand Down
10 changes: 9 additions & 1 deletion rich/live.py
Expand Up @@ -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()
Expand Down

0 comments on commit 5ccf4ed

Please sign in to comment.