Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wandering007 opened this issue Dec 14, 2017 · 29 comments
Closed

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

wandering007 opened this issue Dec 14, 2017 · 29 comments
Labels
need-feedback 📢 We need your response (question) question/docs ‽ Documentation clarification candidate

Comments

@wandering007
Copy link

wandering007 commented Dec 14, 2017

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
Copy link

+1

@casperdcl
Copy link
Sponsor Member

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

@casperdcl casperdcl added question/docs ‽ Documentation clarification candidate need-feedback 📢 We need your response (question) labels Feb 26, 2018
@wandering007
Copy link
Author

wandering007 commented Feb 26, 2018

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

@casperdcl
Copy link
Sponsor Member

closed (#488)

@acheshkov
Copy link

acheshkov commented Aug 1, 2018

the problem still exists

@casperdcl
Copy link
Sponsor Member

@acheshkov on which version of tqdm?

@acheshkov
Copy link

@casperdcl , 4.24.0

@ghost
Copy link

ghost commented Dec 28, 2018

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
Copy link

GuillaumeLeclerc commented Jan 4, 2019

Same error 4.28.1

@HuangKY
Copy link

HuangKY commented May 8, 2020

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
Copy link

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

@AlexVeuthey
Copy link

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
Copy link

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
Copy link
Sponsor Member

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

@Eliran-Turgeman
Copy link

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
Copy link
Sponsor Member

no, you need:

with tqdm(desc="Writing to File"bar_format=BAR_DEFAULT_VIEWtotal=intersection_df[0].count()) as pbar:
        with open(output'w'as f:
            for idxrow 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
Copy link

houseofai commented Nov 26, 2020

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
Copy link

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
Copy link

brianbruggeman commented Oct 21, 2021

@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
Copy link

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
Copy link

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

@WangqaVAD
Copy link

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

@thistlillo
Copy link

The bug is still among us.

@Artemka1806
Copy link

+1

2 similar comments
@Dv1t
Copy link

Dv1t commented Dec 21, 2023

+1

@ashutoshbk
Copy link

+1

@joysky77
Copy link

+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
Copy link

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

@superleesa
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-feedback 📢 We need your response (question) question/docs ‽ Documentation clarification candidate
Projects
None yet
Development

No branches or pull requests