tqdm / tqdm

:zap: A Fast, Extensible Progress Bar for Python and CLI
https://tqdm.github.io
Other
28.67k stars 1.36k forks source link

AttributeError: 'tqdm' object has no attribute 'disable' #487

Closed wandering007 closed 6 years ago

wandering007 commented 6 years ago

tqdm achieved maximum iterations and got the following errors:

RecursionError: maximum recursion depth exceeded
Exception ignored in: <object repr() failed>
Traceback (most recent call last):
  File "/home/changmao/miniconda3/lib/python3.5/site-packages/tqdm/_tqdm.py", line 891, in __del__
    self.close()
  File "/home/changmao/miniconda3/lib/python3.5/site-packages/tqdm/_tqdm.py", line 1102, in close
    if self.disable:
AttributeError: 'tqdm' object has no attribute 'disable'

1) How to increase the maximum recursion depth? 2) it seems a bug.

kaufmann42 commented 6 years ago

+1

casperdcl commented 6 years ago

could you provide a basic bit of code which lets us reproduce this error?

wandering007 commented 6 years ago

@casperdcl Sorry I cannot, I almost forget it now... @kaufmann42 Could you provide it? Thanks.

casperdcl commented 6 years ago

closed (#488)

acheshkov commented 6 years ago

the problem still exists

casperdcl commented 6 years ago

@acheshkov on which version of tqdm?

acheshkov commented 6 years ago

@casperdcl , 4.24.0

ghost commented 5 years ago

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'

GuillaumeLeclerc commented 5 years ago

Same error 4.28.1

HuangKY commented 4 years ago

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

MuyangDu commented 4 years ago

Same error here with the latest version. Please reopen the issue.

AlexVeuthey commented 4 years ago

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.

Eliran-Turgeman commented 3 years ago

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'

casperdcl commented 3 years ago

Please use with tqdm(...) or pbar.close() as you would do with files.

Eliran-Turgeman commented 3 years ago

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'

casperdcl commented 3 years ago

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)

houseofai commented 3 years ago

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

PaleNeutron commented 3 years ago

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

brianbruggeman commented 3 years ago

@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__.

brianbruggeman commented 3 years ago

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
WangqaVAD commented 1 year ago

原因很简单,你们的数据集吧文件夹内部有文件是错误类型,去检查一下数据集

WangqaVAD commented 1 year ago

The reason is very simple. There are files in your dataset folder that are of the wrong type. Go check the dataset

thistlillo commented 1 year ago

The bug is still among us.

Artemka1806 commented 1 year ago

+1

Dv1t commented 10 months ago

+1

ashutoshbk commented 9 months ago

+1

joysky77 commented 8 months ago

+1

Traceback (most recent call last): File "\app\stock_third_web__main.py", line 1, in from stock_third_web.app import main File "\app\stock_third_web\app.py", line 33, in stock_board_industry_summary_ths_df = ak.stock_board_industry_summary_ths() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\app_packages\akshare\stock_feature\stock_board_industry_ths.py", line 617, in stock_board_industry_summary_ths for page in tqdm(range(1, int(page_num) + 1), leave=False): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\app_packages\tqdm\std.py", line 1098, in init self.refresh(lock_args=self.lock_args) File "\app_packages\tqdm\std.py", line 1347, in refresh self.display() File "\app_packages\tqdm\std.py", line 1495, in display self.sp(self.str() if msg is None else msg) File "\app_packages\tqdm\std.py", line 459, in print_status fp_write('\r' + s + (' ' * max(last_len[0] - len_s, 0))) File "\app_packages\tqdm\std.py", line 452, in fp_write fp.write(str(s)) ^^^^^^^^ File "\app_packages\tqdm\utils.py", line 140, in getattr__ return getattr(self._wrapped, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'write'

2091418166 commented 7 months ago

I changed the tqdm version to 4.19.9 which solved the problem.

superleesa commented 7 months ago

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.

MaxDall commented 4 months ago

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.

apacha commented 3 months ago

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.

Hongru0306 commented 1 week ago

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.