-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Create a single cancel callback for each unique input. #2599
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d13a917
Create a single cancel callback for each unique input.
T4rk1n b5c1287
Fix cancel with manager from parameter.
T4rk1n b9a07a0
Add test page cancel.
T4rk1n 050b85e
Fix cancel tests.
T4rk1n 3466998
Wait for worker to be ready.
T4rk1n 384e12a
Merge branch 'dev' into fix/#2588
T4rk1n bc38c13
Rename cancel -> shared_cancel
T4rk1n da66cb1
Update changelog.
T4rk1n 1974bf1
build
T4rk1n 909e39c
build
T4rk1n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from dash import Dash, Input, Output, dcc, html, page_container, register_page | ||
|
||
import time | ||
|
||
from tests.integration.long_callback.utils import get_long_callback_manager | ||
|
||
long_callback_manager = get_long_callback_manager() | ||
handle = long_callback_manager.handle | ||
|
||
|
||
app = Dash( | ||
__name__, | ||
use_pages=True, | ||
pages_folder="", | ||
long_callback_manager=long_callback_manager, | ||
) | ||
|
||
app.layout = html.Div( | ||
[ | ||
dcc.Link("page1", "/"), | ||
dcc.Link("page2", "/2"), | ||
html.Button("Cancel", id="cancel"), | ||
page_container, | ||
] | ||
) | ||
|
||
|
||
register_page( | ||
"one", | ||
"/", | ||
layout=html.Div( | ||
[ | ||
html.Button("start", id="start1"), | ||
html.Button("cancel1", id="cancel1"), | ||
html.Div("idle", id="progress1"), | ||
html.Div("initial", id="output1"), | ||
] | ||
), | ||
) | ||
register_page( | ||
"two", | ||
"/2", | ||
layout=html.Div( | ||
[ | ||
html.Button("start2", id="start2"), | ||
html.Button("cancel2", id="cancel2"), | ||
html.Div("idle", id="progress2"), | ||
html.Div("initial", id="output2"), | ||
] | ||
), | ||
) | ||
|
||
|
||
@app.callback( | ||
Output("output1", "children"), | ||
Input("start1", "n_clicks"), | ||
running=[ | ||
(Output("progress1", "children"), "running", "idle"), | ||
], | ||
cancel=[ | ||
Input("cancel1", "n_clicks"), | ||
Input("cancel", "n_clicks"), | ||
], | ||
background=True, | ||
prevent_initial_call=True, | ||
interval=300, | ||
) | ||
def on_click1(n_clicks): | ||
time.sleep(2) | ||
return f"Click {n_clicks}" | ||
|
||
|
||
@app.callback( | ||
Output("output2", "children"), | ||
Input("start2", "n_clicks"), | ||
running=[ | ||
(Output("progress2", "children"), "running", "idle"), | ||
], | ||
cancel=[ | ||
Input("cancel2", "n_clicks"), | ||
Input("cancel", "n_clicks"), | ||
], | ||
background=True, | ||
prevent_initial_call=True, | ||
interval=300, | ||
) | ||
def on_click1(n_clicks): | ||
time.sleep(2) | ||
return f"Click {n_clicks}" | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What is the purpose of having 2 pages for this test?
As far as I can tell, this effectively tests the same thing twice (once for each page).
Did you mean to test switching pages while a callback is pending? Or do I misunderstand what you're looking for in this test?
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.
Before you couldn't use the same input for multiple background callbacks and if you used one that is on every page and one that is only on one page it also bugged.
Testing page switching is not easy to get feedback for the cancellation, this test just use button instead with the cases above.
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.
Ahhh, I see now. I missed that
#cancel
persists across pages.Maybe this would be easier to understand at a glance if
cancel
was named something more descriptive likeshared_cancel
orpersistent_cancel
.Just a minor thought, otherwise this looks great to me.