Skip to content

Commit

Permalink
cleaner tqdm_notebook exit when not run in a notebook (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
to266 authored and lrq3000 committed Sep 15, 2016
1 parent 1167fed commit 166a820
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tqdm/_tqdm_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,17 @@ def update(self, *args, **kwargs):

def close(self, *args, **kwargs):
super(tqdm_notebook, self).close(*args, **kwargs)
# Try to detect if there was an error or KeyboardInterrupt
# in manual mode: if n < total, things probably got wrong
if self.total and self.n < self.total:
self.sp(bar_style='danger')
else:
if self.leave:
self.sp(bar_style='success')
# If it was not run in a notebook, sp is not assigned, check for it
if hasattr(self, 'sp'):
# Try to detect if there was an error or KeyboardInterrupt
# in manual mode: if n < total, things probably got wrong
if self.total and self.n < self.total:
self.sp(bar_style='danger')
else:
self.sp(close=True)
if self.leave:
self.sp(bar_style='success')
else:
self.sp(close=True)

def moveto(*args, **kwargs):
# void -> avoid extraneous `\n` in IPython output cell
Expand Down

0 comments on commit 166a820

Please sign in to comment.