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
Add an option to log progress while saving animations #13564
Conversation
I would not bother adding a new parameter for that, but just always log the progress at INFO level. |
Wouldn't it be reasonable to offer a generic callback, so that e.g. GUIs could do their own progress display? |
@anntzer the |
@timhoffm I don't know. The current PR is simple and straight forward. But maybe there a good reasons to use a callback instead. Since I'm not a main developer of this library, I think someone else should decide this. |
But info-level logs are not displayed by default; you need to set the log level explicitly to see them. So it's no big deal to emit a bunch of logs at that level (well, preferably not at import time or when doing really common operations, but I think logging every frame on animation saves is just fine). |
Side note: In my case, I load many numpy arrays from disc and plot each of them with the animation tool. When printing a log for each frame, it will be difficult to keep track, which animation is currently processed and what the overall progress of the script is. That is why I provided this parameter. |
My argument for a callback: In many cases (and the default) a progress indicator is not necessary. But when the progress should be indicated, use cases can be quite diverse, which cannot be met with a hard-coded logging call. Instead we should offer a simple way to flexibly hook in the desired functionality. That works via a callback, e.g.
or
or
|
A callback is fine for me. |
The only question: Should it have one argument giving the current frame or should there be a second argument giving the total number of frames? While strictly speaking, the first is sufficient (you can get the total number in a different way), it may be handy to have the total number passed as well. |
Its a bit of a steep climb for the naive user to write a callback; if we are adding a kwarg anyways, perhaps its OK to let this PR is as-is, and let a future PR allow |
I'm against providing a simple logging functionality. Partly, because it's just one special case, and I don't see that it's more suitable than other mechanisms. Partly, because we're getting into naming issues for the parameter. Adding a callback is not more difficult than Conversely, logging needs understanding/adaption of the log levels. This is not a naive user topic. Just emitting infos will not work. Furthermore, I argue that getting progress feedback for animation saving is not a required feature for the naive user. We don't have to bend the API for them on this feature. It's off by default and the user has to consult the docs anyway. We can add a simple example such as |
Replaced the parameter with a callback. Is the PR in a good state now? Anything else I should adjust? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essentially, this is good. Only some minor stylistic issues.
Adjusted the style according to your comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please work out the formatting issues to get CI pass.
- Doc build fails due to a ReST formatting issue.
- flake8 (Travis run) complains about too long lines.
👍 This is a nice new feature! It looks like you could also inject This will definitely need an entry in |
What do you exactly mean with |
For a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from total_frames=None
and the what's new entry, this is ready to go.
752ea1d
to
8bf2bef
Compare
I squashed the changes, is there anything else to do? |
I don't think there's anything more you need to do. We just need a second review from one of the core devs. |
perfect, thank you for your support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone can merge after progress_callback is made keyword only (or if a core dev thinks it's not worth it).
Doc failure is is only due to being based on the recent problems with warnings in doc build. Would be fixed by rebasing, but saving the hassle here. |
…564-on-v3.1.x Backport PR #13564 on branch v3.1.x (Add an option to log progress while saving animations)
Would have preferred to not have had this backported, but definitely not worth reverting the backport. |
PR Summary
Closes #13561
Adds a parameter
log_progress
toanim.save(output_path, writer, log_progress=0)
Parameter description:
log_progress : int, optional
Controls the frequency of progress information written
during execution to the 'info' log. With log_progress=n
the progress information is written every time n frames
are processed. log_progress=0 disables this feature.
PR Checklist