@@ -145,7 +145,7 @@ def status_printer(_, total=None, desc=None, ncols=None):
145145
146146 def display (self , msg = None , pos = None ,
147147 # additional signals
148- close = False , bar_style = None ):
148+ close = False , bar_style = None , check_delay = True ):
149149 # Note: contrary to native tqdm, msg='' does NOT clear bar
150150 # goal is to keep all infos if error happens so user knows
151151 # at which iteration the loop failed.
@@ -190,6 +190,10 @@ def display(self, msg=None, pos=None,
190190 except AttributeError :
191191 self .container .visible = False
192192
193+ if check_delay and self .delay > 0 and not self .displayed :
194+ display (self .container )
195+ self .displayed = True
196+
193197 @property
194198 def colour (self ):
195199 if hasattr (self , 'container' ):
@@ -243,7 +247,7 @@ def __init__(self, *args, **kwargs):
243247
244248 # Print initial bar state
245249 if not self .disable :
246- self .display ()
250+ self .display (check_delay = False )
247251
248252 def __iter__ (self ):
249253 try :
@@ -258,11 +262,6 @@ def __iter__(self):
258262 # since this could be a shared bar which the user will `reset()`
259263
260264 def update (self , n = 1 ):
261- if self .disable :
262- return
263- if not self .displayed and self .delay > 0 :
264- display (self .container )
265- self .displayed = True
266265 try :
267266 return super (tqdm_notebook , self ).update (n = n )
268267 # NB: except ... [ as ...] breaks IPython async KeyboardInterrupt
@@ -275,16 +274,18 @@ def update(self, n=1):
275274 # since this could be a shared bar which the user will `reset()`
276275
277276 def close (self ):
277+ if self .disable :
278+ return
278279 super (tqdm_notebook , self ).close ()
279280 # Try to detect if there was an error or KeyboardInterrupt
280281 # in manual mode: if n < total, things probably got wrong
281282 if self .total and self .n < self .total :
282- self .disp (bar_style = 'danger' )
283+ self .disp (bar_style = 'danger' , check_delay = False )
283284 else :
284285 if self .leave :
285- self .disp (bar_style = 'success' )
286+ self .disp (bar_style = 'success' , check_delay = False )
286287 else :
287- self .disp (close = True )
288+ self .disp (close = True , check_delay = False )
288289
289290 def clear (self , * _ , ** __ ):
290291 pass
0 commit comments