AttributeError: type object 'tqdm' has no attribute '_lock'
NONE
Deleting a class (**not instance**) attribute might be invalid in this case, which is `tqdm` doing in `ensure_lock`.

```python
from tqdm import tqdm as old_tqdm

class tqdm1(old_tqdm):
     def __delattr__(self, attr):
        try:
            super().__delattr__(attr)
        except AttributeError:
            if attr != '_lock':
                print(attr)
                raise

class Meta(type):
    def __delattr__(cls, name):
        if name == "_lock":
            return  
        return super().__delattr__(name)
    
class tqdm2(old_tqdm, metaclass=Meta):
    pass

del tqdm2._lock
del tqdm1._lock # error
```

https://github.com/huggingface/datasets/blob/e71b0b19d79c7531f9b9bea7c09916b5f6157f42/src/datasets/utils/tqdm.py#L104-L122
2025-06-30T15:58:04Z
https://github.com/huggingface/datasets/issues/7660#issuecomment-3019757469
https://api.github.com/repos/huggingface/datasets/issues/7660
IC_kwDODunzps6z_ded
https://api.github.com/repos/huggingface/datasets/issues/comments/3019757469/reactions
2025-06-30T16:07:45Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3019757469
https://avatars.githubusercontent.com/u/44766273?v=4
https://api.github.com/users/Hypothesis-Z/events{/privacy}
https://api.github.com/users/Hypothesis-Z/followers
https://api.github.com/users/Hypothesis-Z/following{/other_user}
https://api.github.com/users/Hypothesis-Z/gists{/gist_id}
https://github.com/Hypothesis-Z
Hypothesis-Z
MDQ6VXNlcjQ0NzY2Mjcz
https://api.github.com/users/Hypothesis-Z/orgs
https://api.github.com/users/Hypothesis-Z/received_events
https://api.github.com/users/Hypothesis-Z/repos
https://api.github.com/users/Hypothesis-Z/starred{/owner}{/repo}
https://api.github.com/users/Hypothesis-Z/subscriptions
User
https://api.github.com/users/Hypothesis-Z
public
NONE
A cheaper option (seems to work in my case):  
```python
from datasets import tqdm as hf_tqdm
hf_tqdm.set_lock(hf_tqdm.get_lock())
```
2025-07-01T02:57:10Z
https://github.com/huggingface/datasets/issues/7660#issuecomment-3021563269
https://api.github.com/repos/huggingface/datasets/issues/7660
IC_kwDODunzps60GWWF
https://api.github.com/repos/huggingface/datasets/issues/comments/3021563269/reactions
2025-07-02T14:42:10Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3021563269
https://avatars.githubusercontent.com/u/44766273?v=4
https://api.github.com/users/Hypothesis-Z/events{/privacy}
https://api.github.com/users/Hypothesis-Z/followers
https://api.github.com/users/Hypothesis-Z/following{/other_user}
https://api.github.com/users/Hypothesis-Z/gists{/gist_id}
https://github.com/Hypothesis-Z
Hypothesis-Z
MDQ6VXNlcjQ0NzY2Mjcz
https://api.github.com/users/Hypothesis-Z/orgs
https://api.github.com/users/Hypothesis-Z/received_events
https://api.github.com/users/Hypothesis-Z/repos
https://api.github.com/users/Hypothesis-Z/starred{/owner}{/repo}
https://api.github.com/users/Hypothesis-Z/subscriptions
User
https://api.github.com/users/Hypothesis-Z
public
### Describe the bug

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

It occurs when I'm trying to load datasets in thread pool.

Issue https://github.com/huggingface/datasets/issues/6066 and PR https://github.com/huggingface/datasets/pull/6067 https://github.com/huggingface/datasets/pull/6068 tried to fix this. 


### Steps to reproduce the bug

Will have to try several times to reproduce the error because it is concerned with threads.
 
1. save some datasets for test
```pythonfrom datasets import Dataset, DatasetDict
import os

os.makedirs("test_dataset_shards", exist_ok=True)

for i in range(10):
    data = Dataset.from_dict({"text": [f"example {j}" for j in range(1000000)]})
    data = DatasetDict({'train': data})
    data.save_to_disk(f"test_dataset_shards/shard_{i}")
```

2. load them in a thread pool 
```python
from datasets import load_from_disk
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor, as_completed
import glob

datas = glob.glob('test_dataset_shards/shard_*')
with ThreadPoolExecutor(max_workers=10) as pool:
    futures = [pool.submit(load_from_disk, it) for it in datas]
datas = []
for future in tqdm(as_completed(futures), total=len(futures)):
    datas.append(future.result())
```

### Expected behavior

no exception raised

### Environment info

datasets==2.19.0
python==3.10