From 1c5ca0f022cba21c59e82ca1c241f73f0735bcb1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 29 Aug 2024 20:38:25 +0200 Subject: [PATCH] chore: improved fix for terminal error --- freqtrade/optimize/hyperopt_output.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/freqtrade/optimize/hyperopt_output.py b/freqtrade/optimize/hyperopt_output.py index e3319c255..c83583d72 100644 --- a/freqtrade/optimize/hyperopt_output.py +++ b/freqtrade/optimize/hyperopt_output.py @@ -59,17 +59,21 @@ class HyperoptOutput: max_rows: Optional[int] = None - if self._streaming and "pytest" not in sys.modules: - ts = get_terminal_size() - # Get terminal size. - # Account for header, borders, and for the progress bar. - # This assumes that lines don't wrap. - if ts.columns < 148: - # If the terminal is too small, we can't display the table properly. - # We will halve the number of rows to display. - max_rows = -(int(ts.lines / 2) - 6) - else: - max_rows = -(ts.lines - 6) + if self._streaming: + try: + ts = get_terminal_size() + # Get terminal size. + # Account for header, borders, and for the progress bar. + # This assumes that lines don't wrap. + if ts.columns < 148: + # If the terminal is too small, we can't display the table properly. + # We will halve the number of rows to display. + max_rows = -(int(ts.lines / 2) - 6) + else: + max_rows = -(ts.lines - 6) + except OSError: + # If we can't get the terminal size, we will just display the last 10 rows. + pass self.__init_table() for r in self._results[max_rows:]: