From 2bd4ff5a90024e6e93a3fb9e0a1acf91fa861cdd Mon Sep 17 00:00:00 2001 From: Andrey Zimovnov Date: Wed, 12 Dec 2018 00:11:04 +0300 Subject: [PATCH] fix tqdm on colab --- tqdm_utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tqdm_utils.py b/tqdm_utils.py index 1a54a16..172a3dc 100644 --- a/tqdm_utils.py +++ b/tqdm_utils.py @@ -47,9 +47,17 @@ def __next__(self): raise StopIteration -def tqdm_notebook_failsafe(*args, **kwargs): +def is_colab(): try: - return tqdm.tqdm_notebook(*args, **kwargs) - except: + import google.colab + return True + except ImportError: + return False + + +def tqdm_notebook_failsafe(*args, **kwargs): + if is_colab(): # tqdm is broken on Google Colab return SimpleTqdm(*args, **kwargs) + else: + return tqdm.tqdm_notebook(*args, **kwargs)