Skip to content

Commit

Permalink
Fix progressbar on jupyter notebooks.
Browse files Browse the repository at this point in the history
Earlier progressbars would not render on notebooks since stdout is not a
tty.  This is now fixed.
  • Loading branch information
prabhuramachandran committed Jan 11, 2021
1 parent 12feca3 commit 522699b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 2 additions & 16 deletions pysph/solver/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from pysph.base import kernels
from compyle.config import get_config
from compyle.profile import print_profile, profile2csv, get_profile_info
from pysph.solver.controller import CommandManager
from pysph.solver.utils import mkdir, load, get_files, get_free_port
from .controller import CommandManager
from .utils import mkdir, load, get_files, get_free_port, is_using_ipython

# conditional parallel imports
from pysph import has_mpi, has_zoltan, in_parallel
Expand All @@ -40,20 +40,6 @@
logger = logging.getLogger(__name__)


def is_using_ipython():
"""Return True if the code is being run from an IPython session or
notebook.
"""
try:
# If this is being run inside an IPython console or notebook
# then this is defined.
__IPYTHON__
except NameError:
return False
else:
return True


def list_all_kernels():
"""Return list of available kernels.
"""
Expand Down
16 changes: 15 additions & 1 deletion pysph/solver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ def get_free_port(start, skip=None):
raise


def is_using_ipython():
"""Return True if the code is being run from an IPython session or
notebook.
"""
try:
# If this is being run inside an IPython console or notebook
# then this is defined.
__IPYTHON__
except NameError:
return False
else:
return True


def check_array(x, y):
"""Check if two arrays are equal with an absolute tolerance of
1e-16."""
Expand Down Expand Up @@ -123,7 +137,7 @@ def __init__(self, ti, tf, show=True, file=None, ascii=False):
self.ascii = ascii
if not ascii and not _supports_unicode(self.file):
self.ascii = True
if not self.file.isatty():
if not self.file.isatty() and not is_using_ipython():
self.show = False
self.display()

Expand Down

0 comments on commit 522699b

Please sign in to comment.