def monitor_call_stack(): if in_ipython(): # see this issue for why: https://github.com/ipython/ipykernel/issues/91 f = sys.__stderr__ else: f = sys.stderr faulthandler.register(signal.SIGUSR1, file=f) print 'To monitor call stack, type this at command line: kill -USR1 {}'.format(os.getpid()) print 'Call stack will be printed to stderr' \ '(in IPython Notebook, this will show in the terminal where you launched the notebook.)'
def verboserate(iterable, *args, **kwargs): """Iterate verbosely. Args: desc (str): prefix for the progress bar total (int): total length of the iterable See more options for tqdm.tqdm. """ progress = tqdm_notebook if in_ipython() else tqdm for val in progress(iterable, *args, **kwargs): yield val
def show(title, directory=''): """If in IPython, show, otherwise, save to file.""" import matplotlib.pyplot as plt if in_ipython(): plt.show() else: # ensure directory exists makedirs(directory) plt.savefig(os.path.join(directory, title) + '.png') # close all figures to conserve memory plt.close('all')
def _print_table(cls, table): if in_ipython(): jupyter_no_margins() display(HTML(table.get_html_string())) else: print(table)