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 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dash/_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ def add_context(*args, **kwargs):
progress = callback_manager.get_progress(cache_key)
if progress:
response["progress"] = {
str(x): progress[i] for i, x in enumerate(progress_outputs)
str(x): progress[i]
for i, x in enumerate(progress_outputs)
if not isinstance(progress[i], NoUpdate)
}

output_value = callback_manager.get_result(cache_key, job_id)
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/long_callback/app_progress_delete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dash import Dash, Input, Output, State, html, clientside_callback
from dash import Dash, Input, Output, State, html, clientside_callback, no_update
import time

from tests.integration.long_callback.utils import get_long_callback_manager
Expand Down Expand Up @@ -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 🔒

set_progress(no_update)
time.sleep(1)
set_progress("stop")
return "done"

Expand Down