Skip to content

Commit

Permalink
closed file: use miniters=inf rather than hacky disable=1
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Sep 28, 2020
1 parent 098745d commit 53a84ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tqdm/std.py
Expand Up @@ -1310,7 +1310,7 @@ def update(self, n=1):

def close(self):
"""Cleanup and (if leave=False) close the progressbar."""
if self.disable is True: # could be truthy yet non-True
if self.disable:
return

# Prevent multiple closures
Expand Down
6 changes: 3 additions & 3 deletions tqdm/utils.py
Expand Up @@ -219,19 +219,19 @@ class DisableOnWriteError(ObjectWrapper):
@staticmethod
def disable_on_exception(tqdm_instance, func):
"""
Quietly set `tqdm_instance.disable=1` if `func` raises `errno=5`.
Quietly set `tqdm_instance.miniters=inf` if `func` raises `errno=5`.
"""
def inner(*args, **kwargs):
try:
return func(*args, **kwargs)
except (IOError, OSError) as e:
if e.errno != 5:
raise
tqdm_instance.disable = 1
tqdm_instance.miniters = float('inf')
except ValueError as e:
if 'closed' not in str(e):
raise
tqdm_instance.disable = 1
tqdm_instance.miniters = float('inf')
return inner

def __init__(self, wrapped, tqdm_instance):
Expand Down

0 comments on commit 53a84ea

Please sign in to comment.