From 2d5a11ceb070d2d7c8cf59321205c03d686d3af5 Mon Sep 17 00:00:00 2001 From: Shaun Walbridge Date: Thu, 22 Apr 2021 18:09:16 -0400 Subject: [PATCH] Check that stdout exposes `isatty` In embedded environments and other contexts, the `sys.stdout` stream may be a custom implementation, and that implementation may not implement `isatty`. Check for its existence before use. --- fastprogress/fastprogress.py | 2 +- nbs/01_fastprogress.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fastprogress/fastprogress.py b/fastprogress/fastprogress.py index 177b327..adbcd6c 100644 --- a/fastprogress/fastprogress.py +++ b/fastprogress/fastprogress.py @@ -208,7 +208,7 @@ def update_graph(self, graphs, x_bounds=None, y_bounds=None, figsize=(6,4)): # Cell def printing(): - return False if NO_BAR else (stdout.isatty() or IN_NOTEBOOK) + return False if NO_BAR else (hasattr(stdout, 'isatty') and stdout.isatty() or IN_NOTEBOOK) # Cell class ConsoleProgressBar(ProgressBar): diff --git a/nbs/01_fastprogress.ipynb b/nbs/01_fastprogress.ipynb index 3e4d8b0..b3c51d4 100644 --- a/nbs/01_fastprogress.ipynb +++ b/nbs/01_fastprogress.ipynb @@ -545,7 +545,7 @@ "source": [ "#export \n", "def printing():\n", - " return False if NO_BAR else (stdout.isatty() or IN_NOTEBOOK)" + " return False if NO_BAR else (hasattr(stdout, 'isatty') and stdout.isatty() or IN_NOTEBOOK)" ] }, {