Closed wandering007 closed 6 years ago
+1
could you provide a basic bit of code which lets us reproduce this error?
@casperdcl Sorry I cannot, I almost forget it now... @kaufmann42 Could you provide it? Thanks.
closed (#488)
the problem still exists
@acheshkov on which version of tqdm
?
@casperdcl , 4.24.0
I am having the same problem with tqdm ...while training a neural network at 493rd epoch (everytime)..
[Epoch 493] Testing Loss: 2.0086 (.Accuracy: 53.64%) Traceback (most recent call last): File "/home/asif/PycharmProjects/RAVDESS/capsule_main.py", line 145, in <module> engine.train(processor, utils.get_iterator(True), maxepoch=config.NUM_EPOCHS, optimizer=optimizer) File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/torchnet/engine/engine.py", line 46, in train self.hook('on_start_epoch', state) File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/torchnet/engine/engine.py", line 31, in hook self.hooks[name](state) File "/home/asif/PycharmProjects/RAVDESS/capsule_main.py", line 71, in on_start_epoch state['iterator'] = tqdm(state['iterator']) File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/tqdm/_tqdm.py", line 801, in __init__ total = len(iterable) File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/tqdm/_tqdm.py", line 920, in __len__ else len(self.iterable) if hasattr(self.iterable, "__len__") File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/tqdm/_tqdm.py", line 920, in __len__ else len(self.iterable) if hasattr(self.iterable, "__len__") File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/tqdm/_tqdm.py", line 920, in __len__ else len(self.iterable) if hasattr(self.iterable, "__len__") [Previous line repeated 490 more times] File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 504, in __len__ return len(self.batch_sampler) File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/torch/utils/data/sampler.py", line 150, in __len__ return (len(self.sampler) + self.batch_size - 1) // self.batch_size File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/torch/utils/data/sampler.py", line 54, in __len__ return len(self.data_source) File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/torchnet/dataset/tensordataset.py", line 46, in __len__ if isinstance(self.data, dict): RecursionError: maximum recursion depth exceeded while calling a Python object Exception ignored in: <function tqdm.__del__ at 0x7f45ff214950> Traceback (most recent call last): File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/tqdm/_tqdm.py", line 931, in __del__ self.close() File "/home/asif/anaconda3/envs/asifml_torch/lib/python3.7/site-packages/tqdm/_tqdm.py", line 1125, in close if self.disable: AttributeError: 'tqdm' object has no attribute 'disable'
Same error 4.28.1
I had the same error (version: 4.46.0)
After some investigation, I found it is based on the version of my Jupyter notebook (iPython; Jupytrer lab).
I have solved it after running this:
conda update jupyter
Same error here with the latest version. Please reopen the issue.
Do you by any chance have a file named _multiprocessing.py
in your path, that's not related to the actual python module multiprocessing
? That's what happened for me, and it created this error. Look carefully at your stacktrace and check if something is called from a file that's not supposed to be there.
On the latest version, 4.53.0, I get a similar error: AttributeError: 'tqdm_asyncio' object has no attribute 'disable'
Code I am executing is:
pbar = tqdm(desc="Writing to File", bar_format=BAR_DEFAULT_VIEW, total=intersection_df[0].count())
with open(output, 'w') as f:
for idx, row in intersection_df.iterrows():
pbar.update(1)
f.write(str(row[0])+"\t"+str(row[1])+"\n")
Just for context, intersection_df
is a dask dataframe (not sure it's relevant).
Before updating to this version, I had version 4.46.0 and the same code generated the error AttributeError: 'tqdm' object has no attribute 'disable'
Please use with tqdm(...)
or pbar.close()
as you would do with files.
Both
with tqdm(desc="Writing to File", bar_format=BAR_DEFAULT_VIEW, total=intersection_df[0].count()):
with open(output, 'w') as f:
for idx, row in intersection_df.iterrows():
tqdm.update(1)
f.write(str(row[0])+"\t"+str(row[1])+"\n")
And
pbar = tqdm(desc="Writing to File", bar_format=BAR_DEFAULT_VIEW, total=intersection_df[0].count())
with open(output, 'w') as f:
for idx, row in intersection_df.iterrows():
pbar.update(1)
f.write(str(row[0])+"\t"+str(row[1])+"\n")
pbar.close()
result in the same error: AttributeError: 'tqdm_asyncio' object has no attribute 'disable'
no, you need:
with tqdm(desc="Writing to File", bar_format=BAR_DEFAULT_VIEW, total=intersection_df[0].count()) as pbar:
with open(output, 'w') as f:
for idx, row in intersection_df.iterrows():
f.write(str(row[0])+"\t"+str(row[1])+"\n")
pbar.update(1)
Then check what lines are actually causing the error (probably incorrect use somewhere else in the code)
Got the same issue with tqdm==4.53.0
import tensorflow as tf
from tqdm import tqdm
#[...] Load TF dataset
dataset_size = tf.data.experimental.cardinality(dataset)
pbar = tqdm(total=dataset_size) # This throw the error
and I get the same issue if I use with tqdm
It seems to happen when the type of the dataset_size
is not an int
. If I change the code to:
dataset_size = tf.data.experimental.cardinality(dataset)
pbar = tqdm(total=dataset_size.numpy())
It works
Why this problem is still here in 2021?
in __init__
if disable:
self.iterable = iterable
self.disable = disable
with self._lock:
self.pos = self._get_free_pos(self)
self._instances.remove(self)
self.n = initial
self.total = total
self.leave = leave
return
It looks really like a bug, self.disable
will not be defined if disable
is not True
@casperdcl
This is still a bug, and I have seen other internal instances where there must be untested code paths explicitly around the self.close
method (here and then here after I made a simple change to make sure disable
was available) when called from __del__
which doesn't have the same kind of protections as __exit__
. As for justification: the exit required the Attribute exception catch implies something happened unexpectedly and we should see a similar exception catch logic for __del__
.
This seems to clean up the problem nicely, albeit harshly. I've placed this in my empty __init__.py
file at the top of my package so that this code below will run first before any other code in my package.
import wrapt
import tqdm.std
methods = ['__del__', 'close']
for method_name in methods:
@wrapt.patch_function_wrapper(tqdm.std.tqdm, method_name)
def new_del(wrapped, instance, args, kwargs):
try:
return wrapped(*args, **kwargs)
except AttributeError:
pass
原因很简单,你们的数据集吧文件夹内部有文件是错误类型,去检查一下数据集
The reason is very simple. There are files in your dataset folder that are of the wrong type. Go check the dataset
The bug is still among us.
+1
+1
+1
+1
Traceback (most recent call last):
File "\app\stock_third_web__main.py", line 1, in
I changed the tqdm version to 4.19.9 which solved the problem.
faced the same error when i was installed it in venv. when i installed it on a conda env, i was able to used it.
This little change between versions 4.49
and 4.50
is the root of the problem for me. I'm using tqdm in a multiprocessing context with multiple processes updating the same bar serialized with dill. If I comment out the mentioned line, everything works just fine. Any Ideas?
Update: Was able to solve this by proxying tqdm with a BaseManager
class TQDMManager(BaseManager):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.register('_tqdm', tqdm)
def tqdm(self, *args, **kwargs) -> tqdm:
# noinspection PyUnresolvedReferences
return self._tqdm(*args, **kwargs)
@contextlib.contextmanager
def get_proxy_tqdm(*args, **kwargs) -> tqdm:
manager = TQDMManager()
try:
manager.start()
yield manager.tqdm(*args, **kwargs)
finally:
manager.shutdown()
Would still be nice if this gets properly solved.
I had a similar problem just now, when I tried to iterate a QuerySet that Django returned. However the problem was, that the queryset was invalid.
Try to replace
for item in tqdm(queryset):
# ...
with
for item in queryset:
# ...
and double-check whether the problem isn't really a problem on the user side.
The reason is very simple. There are files in your dataset folder that are of the wrong type. Go check the dataset
Thanks. My error is because I didn't add the len inside the dataset.
tqdm
achieved maximum iterations and got the following errors:1) How to increase the maximum recursion depth? 2) it seems a bug.