-
-
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
Long callback refactor #2039
Long callback refactor #2039
Conversation
fd9ee13
to
5020c97
Compare
5020c97
to
c5f6fff
Compare
Now that long callbacks are their own category to the renderer rather than creating more regular callbacks, a couple of extra questions:
|
Co-authored-by: Alex Johnson <johnson.alex.c@gmail.com>
Tried an input on the progress, doesn't update, I used
No. |
Pattern matching callbacks are now supported for regular inputs/outputs.
No, progress/running/cancel pattern matching are not supported and will throw an error.
No, the long callback continues until canceled/completed, not sure how that would be done. |
OK. It's going to be a little bit tricky to figure out what that should look like so let's make an issue to come back to this and any other limitations we think could potentially be removed later.
🌟
OK - as long as it's a clear error we can leave that for later as well.
I guess for now I don't really care whether the long callback is allowed to continue (although I'd consider that another limitation, at some point we should make it be canceled as soon as it's known to be moot), but it's important that the first result is ignored when it finally is returned, if at that point there's a different set of inputs. Here's a sample app that shows the desired behavior: if I type something, then change the number of inputs before the output callback has returned, I should not see the intermediate result appear, only the final state. That's how it works right now with regular callbacks, we should ensure it works the same with long callbacks. from dash import Input, Output, State, Dash, html, dcc, callback, ALL
import time
app = Dash(__name__)
app.layout = html.Div(
[
dcc.Dropdown(id="dropdown", value=1, options=list(range(10))),
html.Div([], id="container"),
html.Div(id="out")
],
)
@callback(Output("container", "children"), Input("dropdown", "value"), State("container", "children"))
def make_inputs(n, prev_children):
prev_len = len(prev_children)
if n > prev_len:
return prev_children + [dcc.Input(id={"n": n}, value="") for n in range(prev_len, n)]
return prev_children[:n]
@callback(Output("out", "children"), Input({"n": ALL}, "value"))
def out(vals):
time.sleep(3)
return "+".join(vals)
if __name__ == "__main__":
app.run_server(debug=True) |
It looked like the previous output was discarded in the case of regular callbacks (but job still running). For long pattern matching inputs, the output were not discarded. I've put a check on the output to auto cancel previous jobs. |
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.
💃 Looks great! Once the tests pass, the only other thing I'd like to see before merging is an issue listing the remaining known TODO items:
- pattern-matching with progress / cancel
- progress/cancel in devtools callback graph viz
- do all obsolete jobs now get canceled ASAP, or just the PMC jobs?
- anything else?
Yes I'll create issues for devtools and pattern matching for progress/cancel/running. |
Fix raising errors in long callback triggering an infinite update loop. Fix #1821
no_content
Replace long callback interval polling
interval
milliseconds.long=False
todash.callback
to use instead ofapp.long_callback
.app.long_callback
arguments withlong_
(interval
,running
,cancel
,progress
,progress_default
,cache_args_to_ignore
,manager
)Long callback parity: