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

BF: log_progress: Start progress bar #4326

Merged
merged 1 commit into from Mar 19, 2020
Merged

Conversation

kyleam
Copy link
Contributor

@kyleam kyleam commented Mar 19, 2020

The tqdm progress bars created by log_progress() have two related
issues:

  * Following the first log_progress() call, a bar does not show up
    until after the next call to log_progress() (i.e. the first
    update).  This is because log_progress() does not call
    tqdmProgressBar.start(), so the tqdm class isn't initialized until
    ._create() gets called within .update().

  * At that point, the bar shows up at the initial value.  On the
    second update, it jumps from the initial value to the correct
    value (say, 0 -> 2 if incrementing by 1).  The first update isn't
    displayed because tqdm has logic to skip updates that happen at
    too fast of a rate, so the first .update() call that creates the
    bar gets its update skipped.

Fix these issues by calling .start() on the first call to
log_progress().

Here's a script that shows the problem.

script
import time
import logging
from datalad.log import log_progress

lgr = logging.getLogger("datalad.foo")

nthings = 4

log_progress(lgr.info, "foo",
             "Checking %d things", nthings,
             label="Checking things", total=nthings, unit=" things")

time.sleep(2)
for i in range(nthings):
    log_progress(lgr.info, "foo",
                 "Checking thing %d", i,
                 increment=True, update=1)
    time.sleep(2)

log_progress(lgr.info, "foo",
             "Finished checking %d things", nthings)

The tqdm progress bars created by log_progress() have two related
issues:

  * Following the first log_progress() call, a bar does not show up
    until after the next call to log_progress() (i.e. the first
    update).  This is because log_progress() does not call
    tqdmProgressBar.start(), so the tqdm class isn't initialized until
    ._create() gets called within .update().

  * At that point, the bar shows up at the initial value.  On the
    second update, it jumps from the initial value to the correct
    value (say, 0 -> 2 if incrementing by 1).  The first update isn't
    displayed because tqdm has logic to skip updates that happen at
    too fast of a rate, so the first .update() call that creates the
    bar gets its update skipped.

Fix these issues by calling .start() on the first call to
log_progress().
@codecov
Copy link

@codecov codecov bot commented Mar 19, 2020

Codecov Report

Merging #4326 into maint will increase coverage by 47.03%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##            maint    #4326       +/-   ##
===========================================
+ Coverage   42.58%   89.62%   +47.03%     
===========================================
  Files         275      275               
  Lines       36872    36873        +1     
===========================================
+ Hits        15701    33046    +17345     
+ Misses      21171     3827    -17344     
Impacted Files Coverage Δ
datalad/log.py 89.47% <0.00%> (+47.16%) ⬆️
datalad/core/local/create.py 94.73% <0.00%> (+0.75%) ⬆️
datalad/core/local/tests/test_create.py 100.00% <0.00%> (+0.90%) ⬆️
datalad/ui/progressbars.py 83.10% <0.00%> (+1.35%) ⬆️
datalad/support/external_versions.py 95.62% <0.00%> (+1.45%) ⬆️
datalad/dochelpers.py 87.40% <0.00%> (+1.48%) ⬆️
datalad/support/tests/test_network.py 100.00% <0.00%> (+1.83%) ⬆️
datalad/core/local/status.py 98.03% <0.00%> (+1.96%) ⬆️
datalad/support/tests/test_external_versions.py 91.94% <0.00%> (+2.01%) ⬆️
datalad/support/json_py.py 98.85% <0.00%> (+2.29%) ⬆️
... and 186 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6d7ab1...81ff5d1. Read the comment docs.

@kyleam
Copy link
Contributor Author

@kyleam kyleam commented Mar 19, 2020

@yarikoptic Thanks for taking a look!

@kyleam kyleam merged commit b2a5e7e into datalad:maint Mar 19, 2020
10 of 11 checks passed
@kyleam kyleam deleted the log-progress-start branch Mar 19, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants