diff --git a/progressbar/utils.py b/progressbar/utils.py index 3bbd1519..6cd64aeb 100644 --- a/progressbar/utils.py +++ b/progressbar/utils.py @@ -106,6 +106,16 @@ def get_terminal_size(): # pragma: no cover Returns: width, height: Two integers containing width and height ''' + + try: + # Default to 79 characters for IPython notebooks + ipython = globals().get('get_ipython')() + from ipykernel import zmqshell + if isinstance(ipython, zmqshell.ZMQInteractiveShell): + return 79, 24 + except Exception: # pragma: no cover + pass + try: # This works for Python 3, but not Pypy3. Probably the best method if # it's supported so let's always try @@ -136,15 +146,6 @@ def get_terminal_size(): # pragma: no cover except Exception: # pragma: no cover pass - try: - # Default to 79 characters for IPython notebooks - ipython = globals().get('get_ipython')() - from ipykernel import zmqshell - if isinstance(ipython, zmqshell.ZMQInteractiveShell): - return 79, 24 - except Exception: # pragma: no cover - pass - try: w, h = _get_terminal_size_linux() if w and h: