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

type object tqdm has no attribute '_lock' #457

Closed
JMBokhorst opened this issue Oct 2, 2017 · 19 comments
Closed

type object tqdm has no attribute '_lock' #457

JMBokhorst opened this issue Oct 2, 2017 · 19 comments
Assignees
Labels
p0-bug-critical ☢ Exception rasing
Milestone

Comments

@JMBokhorst
Copy link

JMBokhorst commented Oct 2, 2017

Hello,

I have been using TQDM for quite a while now with a lot of pleasure. However after running a python script this morning, TQDM has started to generate a error and cannot write anything anymore. I have tried to resolve the issue by reinstalling tqdm without succes. I couldn't found any solution to this problem, so I hope you guys can give a clue to what the problem is.

OS: MacOSX 10.12
Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin

$conda list |grep tqdm
tqdm 4.18.0
tqdm 4.18.0 py_0 conda-forge

Code:
from tqdm import tqdm
tqdm.write("hello")
Traceback (most recent call last):
File "", line 1, in
File "/Users/john-melle/anaconda/lib/python3.6/site-packages/tqdm/_tqdm.py", line 497, in write
with cls.external_write_mode(file=file, nolock=nolock):
File "/Users/john-melle/anaconda/lib/python3.6/contextlib.py", line 82, in enter
return next(self.gen)
File "/Users/john-melle/anaconda/lib/python3.6/site-packages/tqdm/_tqdm.py", line 512, in external_write_mode
cls._lock.acquire()
AttributeError: type object 'tqdm' has no attribute '_lock'

@andy-esch
Copy link

andy-esch commented Oct 2, 2017

I'm getting the same error via my CI: https://travis-ci.org/CartoDB/cartoframes/jobs/282396234#L676-L682

We were previously on 4.17.1 but since 4.18.0 has been released our tests are failing from this AttributeError on _lock

@casperdcl
Copy link
Sponsor Member

casperdcl commented Oct 2, 2017

Sorry about this. The way it's done now, you need to have initialised at least one tqdm instance before you can call tqdm.write

so

from tqdm import tqdm
tqdm(disable=True, total=0)  # initialise internal lock

tqdm.write("test")

should work.

You could also do

from tqdm import tqdm
from multiprocessing import Lock
tqdm.set_lock(Lock())  # manually set internal lock

tqdm.write("test")

instead to manually set the internal lock.

Will change this all ASAP to not require any of this.

@casperdcl casperdcl self-assigned this Oct 2, 2017
@casperdcl casperdcl added this to the v5.0.0 milestone Oct 2, 2017
@casperdcl casperdcl added the p0-bug-critical ☢ Exception rasing label Oct 2, 2017
casperdcl added a commit that referenced this issue Oct 2, 2017
@casperdcl
Copy link
Sponsor Member

Could you try the devel branch (commit above) to verify it fixes your problem without altering your code as suggested above?

@andy-esch
Copy link

Yep, will do!

@andy-esch
Copy link

After installing the devel branch, my tests are running perfectly.

@casperdcl
Copy link
Sponsor Member

casperdcl commented Oct 3, 2017

great, you probably need to put tqdm!=4.18.0 in your dependencies. Will release a newer version soon

@andy-esch
Copy link

Nice, thanks for the speedy response. I love tqdm :)

@JMBokhorst
Copy link
Author

Tests are also running perfectly with the devel branch here! Thanks for the quick response! :)

@casperdcl
Copy link
Sponsor Member

fixed in master now

@asanakoy
Copy link

Still having the same issue with tqdm 4.19.4

~/.local/lib/python2.7/site-packages/tqdm/_tqdm.pyc in __new__(cls, *args, **kwargs)
    449         if "_instances" not in cls.__dict__:
    450             cls._instances = WeakSet()
--> 451         with cls._lock:
    452             cls._instances.add(instance)
    453         # Create the monitoring thread

AttributeError: type object 'tqdm' has no attribute '_lock'

@casperdcl
Copy link
Sponsor Member

argh. really

@casperdcl casperdcl reopened this Oct 18, 2017
@casperdcl
Copy link
Sponsor Member

is this consistently reproducible?

@asanakoy
Copy link

I have rolled back to 4.17. It's not crashing any more. But before that it crashed every time I used tqdm.tqdm.

casperdcl added a commit that referenced this issue Oct 18, 2017
@casperdcl
Copy link
Sponsor Member

could you check if the current devel branch fixes this issue for you?

@casperdcl
Copy link
Sponsor Member

@asanakoy ?

@craig-warren
Copy link

I am experiencing this issue since updating to 4.29.0 and Python 3.7.2 on macOS 10.14.

File "/Users/cwarren/miniconda3/envs/gprMax/lib/python3.7/site-packages/tqdm/_tqdm.py", line 540, in external_write_mode
    cls._lock.acquire()
AttributeError: type object 'tqdm' has no attribute '_lock'

If I downgrade tqdm to 4.28.1 with the same environment, the issue goes away.

@casperdcl
Copy link
Sponsor Member

@mjstevens777 might need a look?

@mjstevens777
Copy link
Contributor

I'm sorry, I wasn't aware of that part of the API. I opened a PR.

casperdcl added a commit that referenced this issue Jan 11, 2019
yesimon added a commit to yesimon/bioconda-utils that referenced this issue Jan 15, 2019
Prevent this bug from occurring tqdm/tqdm#457
@leolivier
Copy link

Hi, experiencing again the same issue in 2024:
AttributeError: type object 'tqdm' has no attribute '_lock'

The whole stacktrace is here:

Traceback (most recent call last):
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 542, in _run_script
    exec(code, module.__dict__)
  File "C:\DEV\mobahome\devts\ollama-rag\local_rag_app.py", line 65, in <module>
    page()
  File "C:\DEV\mobahome\devts\ollama-rag\local_rag_app.py", line 44, in page
    st.session_state["assistant"] = ChatPDF()
                                    ^^^^^^^^^
  File "C:\DEV\mobahome\devts\ollama-rag\local_rag.py", line 39, in __init__
    embedding_function=FastEmbedEmbeddings(),
                       ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\pydantic\v1\main.py", line 339, in __init__
    values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\pydantic\v1\main.py", line 1100, in validate_model
    values = validator(cls_, values)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\langchain_community\embeddings\fastembed.py", line 67, in validate_environment
    values["_model"] = TextEmbedding(
                       ^^^^^^^^^^^^^^
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\fastembed\text\text_embedding.py", line 59, in __init__
    self.model = embedding(model_name, cache_dir, threads, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\fastembed\text\onnx_embedding.py", line 183, in __init__
    self._model_dir = self.download_model(self._model_description, self._cache_dir)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\fastembed\common\model_management.py", line 189, in download_model
    return Path(cls.download_files_from_huggingface(hf_source, cache_dir=str(cache_dir)))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\fastembed\common\model_management.py", line 85, in download_files_from_huggingface
    return snapshot_download(
           ^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\huggingface_hub\utils\_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\huggingface_hub\_snapshot_download.py", line 308, in snapshot_download
    thread_map(
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\tqdm\contrib\concurrent.py", line 69, in thread_map
    return _executor_map(ThreadPoolExecutor, fn, *iterables, **tqdm_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\tqdm\contrib\concurrent.py", line 47, in _executor_map
    with ensure_lock(tqdm_class, lock_name=lock_name) as lk:
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\contextlib.py", line 144, in __exit__
    next(self.gen)
  File "C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag\Lib\site-packages\tqdm\contrib\concurrent.py", line 24, in ensure_lock
    del tqdm_class._lock
        ^^^^^^^^^^^^^^^^
AttributeError: type object 'tqdm' has no attribute '_lock'

and the version is 4.66.2

(basic-rag) C:\DEV\mobahome\devts\ollama-rag>conda list tqdm
# packages in environment at C:\Users\olivier_levillain\AppData\Local\miniconda3\envs\basic-rag:
#
# Name                    Version                   Build  Channel
tqdm                      4.66.2                   pypi_0    pypi

I used the same code on another machine with no issue, but I don't have the version number on this other machine...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p0-bug-critical ☢ Exception rasing
Projects
None yet
Development

No branches or pull requests

7 participants