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

Cannot reset if total was initialized as 0 (zero) #1433

Closed
5 of 6 tasks
fireattack opened this issue Feb 22, 2023 · 2 comments
Closed
5 of 6 tasks

Cannot reset if total was initialized as 0 (zero) #1433

fireattack opened this issue Feb 22, 2023 · 2 comments

Comments

@fireattack
Copy link

fireattack commented Feb 22, 2023

  • I have marked all applicable categories:
    • exception-raising bug
    • visual output bug
  • I have visited the source website, and in particular
    read the known issues
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and
    environment, where applicable: 4.64.1 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] win32

When a tqdm object is initialized with total=0, reset(total={a number}) no longer works.

STR:

from tqdm import tqdm
import time


bar = tqdm(total=0)

def upload_chunk(chunk_no, chunks):
    size = 1024*1024*5
    if bar:
        bar.desc = f'chunk {chunk_no + 1}/{chunks}'
        bar.reset(total=size)
    def gen():
        offset = 0
        while True:
            if offset < size:
                update_chunk = 1024*1000
                time.sleep(0.1)
                yield 'a'
                offset += update_chunk
                if bar:
                    bar.update(update_chunk)
            else:
                break
    _ = list(gen())

upload_chunk(0, 100)
bar.close()
print('Done!')
@dargudear
Copy link

if bar: is evaluated to false because of following definition

    def __bool__(self):
        if self.total is not None:
            return self.total > 0

Instead of checking of bool value of bar check if bar is not None in your code.

@fireattack
Copy link
Author

Wow, thanks! That explains it.

My bad for not catching that it never actually reaches bar.reset.

Again, thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants