Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Update progress after iteration (fix #651) #706
Here's an initial stab at #651, which I'm submitting for discussion.
Delaying the status update to after the iteration also fixed the ETA.
from time import sleep from click import progressbar with progressbar(range(10)) as bar: for _ in bar: sleep(1)
Using a generator to update the progress after the iteration rounds fixes the ETA, and the progress starts at 0% until the first iteration is done, as was requested in the ticket. Only when the last item has been iterated over, and processed by the user's block of code, will the statusbar show 100%.
with progressbar(range(10)) as bar: for _ in bar: sleep(1)
Any style or design notions that are broken in this draft change?
Reported "off by one" error is due to the fact that an interator is used
This commit swaps the iterator for a generator, and changes when the
Updating the status report after the user's code has run allows the
@ThiefMaster couldn't sleep 'till this was sorted. Was less painful than I initially thought and you pointing me in the right direction helped immensely. thanks!
I killed off all but the iter method from the iterator interface, and with the tests passing it doesn't seem to have done any harm. Only risky thing I can imagine with this slaughter is if some user for some reason is relying on there being explicit methods available from the iterator interface. In such case that code will break if this change is merged.
With this update, any other reflections on the PR?