snorkel-team / snorkel

A system for quickly generating training data with weak supervision
https://snorkel.org
Apache License 2.0
5.81k stars 857 forks source link

Switch tqdm to jupyter notebook output when needed #1553

Closed jwsmithers closed 4 years ago

jwsmithers commented 4 years ago

When in a IPython environment (jupyter for example), tqdm prints a new line for each progress made. This can get quite annoying 🙂

The solution is to import tqdm notebook version instead: from tqdm.notebook import tqdm So maybe a check, something like from here:

def isnotebook():
    try:
        shell = get_ipython().__class__.__name__
        if shell == 'ZMQInteractiveShell':
            return True   # Jupyter notebook or qtconsole
        elif shell == 'TerminalInteractiveShell':
            return False  # Terminal running IPython
        else:
            return False  # Other type (?)
    except NameError:
        return False      # Probably standard Python interpreter

The alternative could be just a flag: is_notebook=True.

If there's already a solution to this, great and sorry for the noise! 🙂

jwsmithers commented 4 years ago

So, after restarting my kernel this seems to have been resolved. Not sure what happened, but awesome!