20
20
PreventUpdate ,
21
21
WildcardInLongCallback ,
22
22
MissingLongCallbackManagerError ,
23
- LongCallbackError ,
23
+ BackgroundCallbackError ,
24
24
ImportedInsideCallbackError ,
25
25
)
26
26
39
39
)
40
40
41
41
from . import _validate
42
- from .long_callback .managers import BaseLongCallbackManager
42
+ from .background_callback .managers import BaseBackgroundCallbackManager
43
43
from ._callback_context import context_value
44
44
45
45
@@ -72,7 +72,7 @@ def callback(
72
72
progress_default : Any = None ,
73
73
running : Optional [List [Tuple [Output , Any , Any ]]] = None ,
74
74
cancel : Optional [List [Input ]] = None ,
75
- manager : Optional [BaseLongCallbackManager ] = None ,
75
+ manager : Optional [BaseBackgroundCallbackManager ] = None ,
76
76
cache_args_to_ignore : Optional [list ] = None ,
77
77
on_error : Optional [Callable [[Exception ], Any ]] = None ,
78
78
** _kwargs ,
@@ -96,11 +96,11 @@ def callback(
96
96
97
97
:Keyword Arguments:
98
98
:param background:
99
- Mark the callback as a long callback to execute in a manager for
99
+ Mark the callback as a background callback to execute in a manager for
100
100
callbacks that take a long time without locking up the Dash app
101
101
or timing out.
102
102
:param manager:
103
- A long callback manager instance. Currently, an instance of one of
103
+ A background callback manager instance. Currently, an instance of one of
104
104
`DiskcacheManager` or `CeleryManager`.
105
105
Defaults to the `background_callback_manager` instance provided to the
106
106
`dash.Dash constructor`.
@@ -144,14 +144,14 @@ def callback(
144
144
this should be a list of argument names as strings. Otherwise,
145
145
this should be a list of argument indices as integers.
146
146
:param interval:
147
- Time to wait between the long callback update requests.
147
+ Time to wait between the background callback update requests.
148
148
:param on_error:
149
149
Function to call when the callback raises an exception. Receives the
150
150
exception object as first argument. The callback_context can be used
151
151
to access the original callback inputs, states and output.
152
152
"""
153
153
154
- long_spec = None
154
+ background_spec = None
155
155
156
156
config_prevent_initial_callbacks = _kwargs .pop (
157
157
"config_prevent_initial_callbacks" , False
@@ -160,54 +160,56 @@ def callback(
160
160
callback_list = _kwargs .pop ("callback_list" , GLOBAL_CALLBACK_LIST )
161
161
162
162
if background :
163
- long_spec : Any = {
163
+ background_spec : Any = {
164
164
"interval" : interval ,
165
165
}
166
166
167
167
if manager :
168
- long_spec ["manager" ] = manager
168
+ background_spec ["manager" ] = manager
169
169
170
170
if progress :
171
- long_spec ["progress" ] = coerce_to_list (progress )
172
- validate_long_inputs ( long_spec ["progress" ])
171
+ background_spec ["progress" ] = coerce_to_list (progress )
172
+ validate_background_inputs ( background_spec ["progress" ])
173
173
174
174
if progress_default :
175
- long_spec ["progressDefault" ] = coerce_to_list (progress_default )
175
+ background_spec ["progressDefault" ] = coerce_to_list (progress_default )
176
176
177
- if not len (long_spec ["progress" ]) == len (long_spec ["progressDefault" ]):
177
+ if not len (background_spec ["progress" ]) == len (
178
+ background_spec ["progressDefault" ]
179
+ ):
178
180
raise Exception (
179
181
"Progress and progress default needs to be of same length"
180
182
)
181
183
182
184
if cancel :
183
185
cancel_inputs = coerce_to_list (cancel )
184
- validate_long_inputs (cancel_inputs )
186
+ validate_background_inputs (cancel_inputs )
185
187
186
- long_spec ["cancel" ] = [c .to_dict () for c in cancel_inputs ]
187
- long_spec ["cancel_inputs" ] = cancel_inputs
188
+ background_spec ["cancel" ] = [c .to_dict () for c in cancel_inputs ]
189
+ background_spec ["cancel_inputs" ] = cancel_inputs
188
190
189
191
if cache_args_to_ignore :
190
- long_spec ["cache_args_to_ignore" ] = cache_args_to_ignore
192
+ background_spec ["cache_args_to_ignore" ] = cache_args_to_ignore
191
193
192
194
return register_callback (
193
195
callback_list ,
194
196
callback_map ,
195
197
config_prevent_initial_callbacks ,
196
198
* _args ,
197
199
** _kwargs ,
198
- long = long_spec ,
200
+ long = background_spec ,
199
201
manager = manager ,
200
202
running = running ,
201
203
on_error = on_error ,
202
204
)
203
205
204
206
205
- def validate_long_inputs (deps ):
207
+ def validate_background_inputs (deps ):
206
208
for dep in deps :
207
209
if dep .has_wildcard ():
208
210
raise WildcardInLongCallback (
209
211
f"""
210
- long callbacks does not support dependencies with
212
+ background callbacks does not support dependencies with
211
213
pattern-matching ids
212
214
Received: { repr (dep )} \n """
213
215
)
@@ -318,7 +320,7 @@ def register_callback(
318
320
multi = True
319
321
has_output = len (output ) > 0
320
322
321
- long = _kwargs .get ("long" )
323
+ background = _kwargs .get ("long" )
322
324
manager = _kwargs .get ("manager" )
323
325
running = _kwargs .get ("running" )
324
326
on_error = _kwargs .get ("on_error" )
@@ -342,7 +344,7 @@ def register_callback(
342
344
flat_state ,
343
345
inputs_state_indices ,
344
346
prevent_initial_call ,
345
- long = long ,
347
+ long = background ,
346
348
manager = manager ,
347
349
dynamic_creator = allow_dynamic_callbacks ,
348
350
running = running ,
@@ -352,23 +354,25 @@ def register_callback(
352
354
# pylint: disable=too-many-locals
353
355
def wrap_func (func ):
354
356
355
- if long is not None :
356
- long_key = BaseLongCallbackManager .register_func (
357
+ if background is not None :
358
+ background_key = BaseBackgroundCallbackManager .register_func (
357
359
func ,
358
- long .get ("progress" ) is not None ,
360
+ background .get ("progress" ) is not None ,
359
361
callback_id ,
360
362
)
361
363
362
364
@wraps (func )
363
365
def add_context (* args , ** kwargs ):
364
366
output_spec = kwargs .pop ("outputs_list" )
365
- app_callback_manager = kwargs .pop ("long_callback_manager " , None )
367
+ app_callback_manager = kwargs .pop ("background_callback_manager " , None )
366
368
367
369
callback_ctx = kwargs .pop (
368
370
"callback_context" , AttributeDict ({"updated_props" : {}})
369
371
)
370
372
app = kwargs .pop ("app" , None )
371
- callback_manager = long and long .get ("manager" , app_callback_manager )
373
+ callback_manager = background and background .get (
374
+ "manager" , app_callback_manager
375
+ )
372
376
error_handler = on_error or kwargs .pop ("app_on_error" , None )
373
377
original_packages = set (ComponentRegistry .registry )
374
378
@@ -384,18 +388,18 @@ def add_context(*args, **kwargs):
384
388
response : dict = {"multi" : True }
385
389
has_update = False
386
390
387
- if long is not None :
391
+ if background is not None :
388
392
if not callback_manager :
389
393
raise MissingLongCallbackManagerError (
390
- "Running `long ` callbacks requires a manager to be installed.\n "
394
+ "Running `background ` callbacks requires a manager to be installed.\n "
391
395
"Available managers:\n "
392
396
"- Diskcache (`pip install dash[diskcache]`) to run callbacks in a separate Process"
393
397
" and store results on the local filesystem.\n "
394
398
"- Celery (`pip install dash[celery]`) to run callbacks in a celery worker"
395
399
" and store results on redis.\n "
396
400
)
397
401
398
- progress_outputs = long .get ("progress" )
402
+ progress_outputs = background .get ("progress" )
399
403
cache_key = flask .request .args .get ("cacheKey" )
400
404
job_id = flask .request .args .get ("job" )
401
405
old_job = flask .request .args .getlist ("oldJob" )
@@ -404,7 +408,7 @@ def add_context(*args, **kwargs):
404
408
func ,
405
409
# Inputs provided as dict is kwargs.
406
410
func_args if func_args else func_kwargs ,
407
- long .get ("cache_args_to_ignore" , []),
411
+ background .get ("cache_args_to_ignore" , []),
408
412
)
409
413
410
414
if old_job :
@@ -414,7 +418,7 @@ def add_context(*args, **kwargs):
414
418
if not cache_key :
415
419
cache_key = current_key
416
420
417
- job_fn = callback_manager .func_registry .get (long_key )
421
+ job_fn = callback_manager .func_registry .get (background_key )
418
422
419
423
ctx_value = AttributeDict (** context_value .get ())
420
424
ctx_value .ignore_register_page = True
@@ -433,11 +437,11 @@ def add_context(*args, **kwargs):
433
437
"job" : job ,
434
438
}
435
439
436
- cancel = long .get ("cancel" )
440
+ cancel = background .get ("cancel" )
437
441
if cancel :
438
442
data ["cancel" ] = cancel
439
443
440
- progress_default = long .get ("progressDefault" )
444
+ progress_default = background .get ("progressDefault" )
441
445
if progress_default :
442
446
data ["progressDefault" ] = {
443
447
str (o ): x
@@ -461,11 +465,11 @@ def add_context(*args, **kwargs):
461
465
462
466
elif (
463
467
isinstance (output_value , dict )
464
- and "long_callback_error " in output_value
468
+ and "background_callback_error " in output_value
465
469
):
466
- error = output_value .get ("long_callback_error " , {})
467
- exc = LongCallbackError (
468
- f"An error occurred inside a long callback: { error ['msg' ]} \n { error ['tb' ]} "
470
+ error = output_value .get ("background_callback_error " , {})
471
+ exc = BackgroundCallbackError (
472
+ f"An error occurred inside a background callback: { error ['msg' ]} \n { error ['tb' ]} "
469
473
)
470
474
if error_handler :
471
475
output_value = error_handler (exc )
@@ -555,7 +559,7 @@ def add_context(*args, **kwargs):
555
559
output_value = []
556
560
flat_output_values = []
557
561
558
- if not long :
562
+ if not background :
559
563
has_update = _set_side_update (callback_ctx , response ) or has_update
560
564
561
565
if not has_update :
0 commit comments