mirror of https://github.com/tqdm/tqdm.git
slight tidy
This commit is contained in:
parent
75ccceef7f
commit
42d7b6e563
|
@ -4,9 +4,9 @@ General helpers required for `tqdm.std`.
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import weakref
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
|
from weakref import proxy
|
||||||
|
|
||||||
# py2/3 compat
|
# py2/3 compat
|
||||||
try:
|
try:
|
||||||
|
@ -138,22 +138,25 @@ class DisableOnWriteError(ObjectWrapper):
|
||||||
"""
|
"""
|
||||||
Quietly set `tqdm_instance.miniters=inf` if `func` raises `errno=5`.
|
Quietly set `tqdm_instance.miniters=inf` if `func` raises `errno=5`.
|
||||||
"""
|
"""
|
||||||
tqdm_instance_ref = weakref.ref(tqdm_instance)
|
tqdm_instance = proxy(tqdm_instance)
|
||||||
|
|
||||||
def inner(*args, **kwargs):
|
def inner(*args, **kwargs):
|
||||||
tqdm_instance = tqdm_instance_ref()
|
|
||||||
try:
|
try:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != 5:
|
if e.errno != 5:
|
||||||
raise
|
raise
|
||||||
if tqdm_instance is not None:
|
try:
|
||||||
tqdm_instance.miniters = float('inf')
|
tqdm_instance.miniters = float('inf')
|
||||||
|
except ReferenceError:
|
||||||
|
pass
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
if 'closed' not in str(e):
|
if 'closed' not in str(e):
|
||||||
raise
|
raise
|
||||||
if tqdm_instance is not None:
|
try:
|
||||||
tqdm_instance.miniters = float('inf')
|
tqdm_instance.miniters = float('inf')
|
||||||
|
except ReferenceError:
|
||||||
|
pass
|
||||||
return inner
|
return inner
|
||||||
|
|
||||||
def __init__(self, wrapped, tqdm_instance):
|
def __init__(self, wrapped, tqdm_instance):
|
||||||
|
|
Loading…
Reference in New Issue