MCPcopy
hub / github.com/plotly/dash / async_add_context

Function async_add_context

dash/_callback.py:808–878  ·  view source on GitHub ↗

Handles async callbacks with context management.

(*args, **kwargs)

Source from the content-addressed store, hash-verified

806
807 @wraps(func)
808 async def async_add_context(*args, **kwargs):
809 """Handles async callbacks with context management."""
810 error_handler = on_error or kwargs.pop("app_on_error", None)
811
812 (
813 output_spec,
814 callback_ctx,
815 func_args,
816 func_kwargs,
817 app,
818 original_packages,
819 has_update,
820 ) = _initialize_context(
821 args, kwargs, inputs_state_indices, has_output, insert_output
822 )
823
824 response: CallbackExecutionResponse = {"multi": True}
825
826 try:
827 if background is not None:
828 adapter = get_app().backend.request_adapter()
829 if not (adapter and adapter.args.get("cacheKey")):
830 return _setup_background_callback(
831 kwargs,
832 background,
833 background_key,
834 func,
835 func_args,
836 func_kwargs,
837 callback_ctx,
838 )
839 output_value, has_update, skip = _update_background_callback(
840 error_handler, callback_ctx, response, kwargs, background, multi
841 )
842 if skip:
843 return output_value
844 else:
845 output_value = await _async_invoke_callback(
846 func, *func_args, **func_kwargs
847 )
848 except PreventUpdate:
849 raise
850 except Exception as err: # pylint: disable=broad-exception-caught
851 if error_handler:
852 output_value = error_handler(err)
853 if output_value is None and output_spec:
854 output_value = NoUpdate()
855 else:
856 raise err
857
858 _prepare_response(
859 output_value,
860 output_spec,
861 multi,
862 response,
863 callback_ctx,
864 app,
865 original_packages,

Callers

nothing calls this directly

Calls 10

get_appFunction · 0.90
_initialize_contextFunction · 0.85
_async_invoke_callbackFunction · 0.85
NoUpdateClass · 0.85
_prepare_responseFunction · 0.85
to_jsonFunction · 0.85
popMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…