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

Set progress no update #2901

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

leeagustin
Copy link
Contributor

Fixes #2846.

While I wasn't able to replicate the error from the issue, I did find that set_progress((no_update, str(total))) sets the progress to 0:
image

This is because the progress bar's value is being set to "[object Object]", which is probably being interpreted as 0. The progress bar's HTML being: <progress id="progress_bar" value="[object Object]" max="5" style="visibility: visible;"></progress>.

I modified it so that if set_progress has no_update for a component's output, that component will not be updated, but the other components—assuming they are not no_update—will be updated.

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks
    • Allows for no_update in background callback set_progress
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

@@ -36,7 +36,9 @@
)
def on_bg_progress(set_progress, _):
set_progress("start")
time.sleep(2)
time.sleep(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to change this to lock to make sure it's not reset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming you meant to write look instead of lock. Would 7437e2b work?

The final results for this test (tests/integration/long_callback/test_basic_long_callback014.py) would be:

  • Using dev
    image
  • Using this PR
    image

In dev, the #progress-counter is 3 because the value gets incremented every time set_progress is called, but it's correctly being left as 2 with this PR's changes.

As for why #progress-output is set back to start in dev, I am not sure 🤔. However, it's correctly being left as stop in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @T4rk1n was referring to multiprocessing.Lock, which you can find in some of the other Dash tests. This can remove the need for any explicit sleep statements, which not only makes the tests faster but also more robust on CI where you never know what else is running on the same hardware and can lead to unexpected delays that will intermittently break tests based on sleep.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was talking about a multiprocessing.Lock.

Basically you would do in the callback

with lock:
    set_progress(no_update)

Then in the test you can also request the lock and do the assertions, so you can be sure the call to set_progress is done before the assertions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh I see, that makes sense. I added the lock in 21bc4b2 🔒

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.

[BUG] no_update is not allowed as an output to set_progress for background progress
3 participants