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

have tqdm call a callback when certain progress has been made #845

Closed
3 of 7 tasks
spott opened this issue Nov 20, 2019 · 9 comments · Fixed by #1019
Closed
3 of 7 tasks

have tqdm call a callback when certain progress has been made #845

spott opened this issue Nov 20, 2019 · 9 comments · Fixed by #1019
Labels
p4-enhancement-future 🧨 On the back burner question/docs ‽ Documentation clarification candidate

Comments

@spott
Copy link

spott commented Nov 20, 2019

  • I have marked all applicable categories:
    • exception-raising bug
    • visual output bug
    • documentation request (i.e. "X is missing from the documentation." If instead I want to ask "how to use X?" I understand [StackOverflow#tqdm] is more appropriate)
    • new feature request
  • I have visited the [source website], and in particular
    read the [known issues]
  • I have searched through the [issue tracker] for duplicates

I would like to be able to have TQDM perform some callback at regular (or calculated) intervals.

For example, I would like tqdm to be able to send a message to slack when I'm 25% done. Or have tqdm send messages to a log file with much less frequency than when it sends to the console or notebook.

I am aware that this can be done by extending tqdm, but I thought it would be something that people might want built-in.

@casperdcl
Copy link
Member

@ThyrixYang fine but probably won't be merged before #815 and/or it gets enough community support

@casperdcl casperdcl added p4-enhancement-future 🧨 On the back burner question/docs ‽ Documentation clarification candidate labels Nov 30, 2019
@casperdcl
Copy link
Member

casperdcl commented Nov 30, 2019

For future ref (manual tqdm.update()):

from tqdm import tqdm as base_tqdm
# or: from tqdm.auto import tqdm as base_tqdm

class tqdm(base_tqdm):
    def update(self, n=1):
        super(tqdm, self).update(n)
        some_callback(n)

The iter(tqdm) version would be much harder to patch.

@spott
Copy link
Author

spott commented Dec 2, 2019

@casperdcl:

Maybe this should change to a documentation change, rather than a feature request... that is pretty simple.

Would this work with the 'auto' tqdm?

@casperdcl
Copy link
Member

casperdcl commented Dec 2, 2019

yes. would work with auto and any other subclass (updated to show this). I labelled it as question which is also used for doc update candidates. The thing is tqdm.update() is usually the callback - not the other way around - so I'm not sure how useful this is...

@LucaCappelletti94
Copy link
Contributor

Any updates on this? I'd love to do an integration with Notipy me that sends you an email every like, 12 hours of progress.

@casperdcl
Copy link
Member

casperdcl added a commit that referenced this issue Aug 8, 2020
@casperdcl
Copy link
Member

casperdcl commented Aug 9, 2020

duplicate of #518 - updated there...

@casperdcl
Copy link
Member

srry not a duplicate

@casperdcl casperdcl reopened this Aug 9, 2020
@casperdcl casperdcl removed the duplicate 🗐 Seen it before label Aug 9, 2020
@casperdcl
Copy link
Member

For future ref (manual tqdm.update()):

from tqdm import tqdm as base_tqdm
# or: from tqdm.auto import tqdm as base_tqdm

class tqdm(base_tqdm):
    def update(self, n=1):
        super(tqdm, self).update(n)
        some_callback(n)

The iter(tqdm) version would be much harder to patch.

I think maybe if update() is changed to return True iff a display was actually triggered, then this could be improved:

from tqdm.auto import tqdm as base_tqdm

class tqdm(base_tqdm):
    def update(self, n=1, always_callback=False):
        if super(tqdm, self).update(n) or always_callback:
            some_callback(**self.format_dict)

casperdcl added a commit that referenced this issue Sep 7, 2020
- fixes #845
- related (but actually opposite of) #518
casperdcl added a commit that referenced this issue Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4-enhancement-future 🧨 On the back burner question/docs ‽ Documentation clarification candidate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants