Skip to content

Long callback refactor #2039

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

Merged
merged 41 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
bfbd59e
Handle long callback errors.
T4rk1n Apr 26, 2022
dbacfcc
:hankey: Add test long callback error.
T4rk1n Apr 26, 2022
ac59e59
Add lock to diskcache
T4rk1n May 6, 2022
e2d3d5e
Fix test long callback error.
T4rk1n May 6, 2022
c3855ef
Merge branch 'dev' into long-callback-errors
T4rk1n May 6, 2022
fb4cef9
Handle no update in celery long callbacks.
T4rk1n May 6, 2022
fa94a40
Use diskcache lock
T4rk1n May 9, 2022
7688306
Stricter no_update check.
T4rk1n May 9, 2022
20c72b9
Handle no update in multi output.
T4rk1n May 9, 2022
2f9fe06
Add long callback test lock.
T4rk1n May 9, 2022
9ed5a3f
Merge branch 'dev' into long-callback-errors
T4rk1n May 17, 2022
9cab5b4
Clean up no_update.
T4rk1n May 17, 2022
9509213
Merge branch 'dev' into long-callback-errors
T4rk1n Jun 10, 2022
3a207ce
Merge branch 'dev' into long-callback-errors
T4rk1n Jun 13, 2022
2b22ff3
Replace long callback interval with request polling handled in renderer.
T4rk1n Jun 13, 2022
c5f6fff
Fix test_grouped_callbacks
T4rk1n Jun 13, 2022
fc9a77b
Fix cbva002
T4rk1n Jun 14, 2022
40bd173
Fix celery cancel.
T4rk1n Jun 14, 2022
28a6d77
Fix callback_map
T4rk1n Jun 14, 2022
1c1c7a2
Update callback docstrings.
T4rk1n Jun 15, 2022
55455f9
Add test short interval.
T4rk1n Jun 15, 2022
cc9b09b
Add error if no manager.
T4rk1n Jun 15, 2022
0501fd9
Fix error message assert
T4rk1n Jun 15, 2022
43e42ea
Remove leftover _NoUpdate.
T4rk1n Jun 20, 2022
de5ee34
Update dash/dash.py
T4rk1n Jun 20, 2022
08356f0
Hide arguments.
T4rk1n Jun 20, 2022
edd7fd6
Add test side update.
T4rk1n Jun 21, 2022
2fd56e9
Redux devtools ignore reloadRequest actions.
T4rk1n Jun 21, 2022
da2b01f
Long callbacks side update to trigger other callbacks.
T4rk1n Jun 21, 2022
bfc3c8f
Add test long callback pattern matching.
T4rk1n Jun 21, 2022
077733c
Add circular check for long callbacks side outputs.
T4rk1n Jun 21, 2022
638dacf
Add test long callback context.
T4rk1n Jun 21, 2022
9df3082
Support callback context in long callbacks.
T4rk1n Jun 21, 2022
ccb53b9
Proper callback_context, replace flask.g context with contextvars.
T4rk1n Jun 22, 2022
8525c73
Fix cancel.
T4rk1n Jun 23, 2022
34bd81d
Back to flask.g for timing_information.
T4rk1n Jun 23, 2022
b2ac6ce
Merge branch 'dev' into long-callback-errors
T4rk1n Jun 23, 2022
02c15dc
Manage previous outdated running jobs.
T4rk1n Jun 28, 2022
a003f5a
Merge branch 'dev' into long-callback-errors
T4rk1n Jun 29, 2022
529ec8e
Lock selenium <=4.2.0
T4rk1n Jun 30, 2022
2fb1cfa
Update changelog.
T4rk1n Jun 30, 2022
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
Prev Previous commit
Next Next commit
Update callback docstrings.
  • Loading branch information
T4rk1n committed Jun 15, 2022
commit 1c1c7a2df1a071d2365dd71913429b91dad978a8
52 changes: 52 additions & 0 deletions dash/_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,58 @@ def callback(
The last, optional argument `prevent_initial_call` causes the callback
not to fire when its outputs are first added to the page. Defaults to
`False` and unlike `app.callback` is not configurable at the app level.

:Keyword Arguments:
:param long:
Mark the callback as a long callback to execute in a manager for
callbacks that take a long time without locking up the Dash app
or timing out.
:param long_manager:
A long callback manager instance. Currently an instance of one of
`DiskcacheLongCallbackManager` or `CeleryLongCallbackManager`.
Defaults to the `long_callback_manager` instance provided to the
`dash.Dash constructor`.
- A diskcache manager (`DiskcacheLongCallbackManager`) that runs callback
logic in a separate process and stores the results to disk using the
diskcache library. This is the easiest backend to use for local
development.
- A Celery manager (`CeleryLongCallbackManager`) that runs callback logic
in a celery worker and returns results to the Dash app through a Celery
broker like RabbitMQ or Redis.
:param long_running:
A list of 3-element tuples. The first element of each tuple should be
an `Output` dependency object referencing a property of a component in
the app layout. The second element is the value that the property
should be set to while the callback is running, and the third element
is the value the property should be set to when the callback completes.
:param long_cancel:
A list of `Input` dependency objects that reference a property of a
component in the app's layout. When the value of this property changes
while a callback is running, the callback is canceled.
Note that the value of the property is not significant, any change in
value will result in the cancellation of the running job (if any).
:param long_progress:
An `Output` dependency grouping that references properties of
components in the app's layout. When provided, the decorated function
will be called with an extra argument as the first argument to the
function. This argument, is a function handle that the decorated
function should call in order to provide updates to the app on its
current progress. This function accepts a single argument, which
correspond to the grouping of properties specified in the provided
`Output` dependency grouping
:param long_progress_default:
A grouping of values that should be assigned to the components
specified by the `progress` argument when the callback is not in
progress. If `progress_default` is not provided, all the dependency
properties specified in `progress` will be set to `None` when the
callback is not running.
:param long_cache_args_to_ignore:
Arguments to ignore when caching is enabled. If callback is configured
with keyword arguments (Input/State provided in a dict),
this should be a list of argument names as strings. Otherwise,
this should be a list of argument indices as integers.
:param long_interval:
Time to wait between the long callback update requests.
"""

long_spec = None
Expand Down
68 changes: 6 additions & 62 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,6 @@ def clientside_callback(self, clientside_function, *args, **kwargs):
**kwargs,
)

# pylint: disable=R0201
def callback(self, *_args, **_kwargs):
"""
Normally used as a decorator, `@app.callback` provides a server-side
Expand All @@ -1139,7 +1138,6 @@ def callback(self, *_args, **_kwargs):
**_kwargs,
)

# pylint: disable=R0201
def long_callback(
self,
*_args,
Expand All @@ -1151,67 +1149,10 @@ def long_callback(
progress_default=None,
cache_args_to_ignore=None,
**_kwargs,
): # pylint: disable=too-many-statements
):
"""
Deprecation Notice, use long

Normally used as a decorator, `@app.long_callback` is an alternative to
`@app.callback` designed for callbacks that take a long time to run,
without locking up the Dash app or timing out.

`@long_callback` is designed to support multiple callback managers.
Two long callback managers are currently implemented:

- A diskcache manager (`DiskcacheLongCallbackManager`) that runs callback
logic in a separate process and stores the results to disk using the
diskcache library. This is the easiest backend to use for local
development.
- A Celery manager (`CeleryLongCallbackManager`) that runs callback logic
in a celery worker and returns results to the Dash app through a Celery
broker like RabbitMQ or Redis.

The following arguments may include any valid arguments to `@app.callback`.
In addition, `@app.long_callback` supports the following optional
keyword arguments:

:Keyword Arguments:
:param manager:
A long callback manager instance. Currently an instance of one of
`DiskcacheLongCallbackManager` or `CeleryLongCallbackManager`.
Defaults to the `long_callback_manager` instance provided to the
`dash.Dash constructor`.
:param running:
A list of 3-element tuples. The first element of each tuple should be
an `Output` dependency object referencing a property of a component in
the app layout. The second element is the value that the property
should be set to while the callback is running, and the third element
is the value the property should be set to when the callback completes.
:param cancel:
A list of `Input` dependency objects that reference a property of a
component in the app's layout. When the value of this property changes
while a callback is running, the callback is canceled.
Note that the value of the property is not significant, any change in
value will result in the cancellation of the running job (if any).
:param progress:
An `Output` dependency grouping that references properties of
components in the app's layout. When provided, the decorated function
will be called with an extra argument as the first argument to the
function. This argument, is a function handle that the decorated
function should call in order to provide updates to the app on its
current progress. This function accepts a single argument, which
correspond to the grouping of properties specified in the provided
`Output` dependency grouping
:param progress_default:
A grouping of values that should be assigned to the components
specified by the `progress` argument when the callback is not in
progress. If `progress_default` is not provided, all the dependency
properties specified in `progress` will be set to `None` when the
callback is not running.
:param cache_args_to_ignore:
Arguments to ignore when caching is enabled. If callback is configured
with keyword arguments (Input/State provided in a dict),
this should be a list of argument names as strings. Otherwise,
this should be a list of argument indices as integers.
Deprecation Notice, long callbacks are now supported natively with regular callbacks,
use `long=True` with `dash.callback` or `app.callback` instead.
"""
return _callback.callback(
*_args,
Expand All @@ -1223,6 +1164,9 @@ def long_callback(
long_running=running,
long_cancel=cancel,
long_cache_args_to_ignore=cache_args_to_ignore,
callback_map=self.callback_map,
callback_list=self._callback_list,
config_prevent_initial_callbacks=self.config.prevent_initial_callbacks,
**_kwargs,
)

Expand Down