MCPcopy Index your code
hub / github.com/plotly/dash / job_fn

Function job_fn

dash/background_callback/managers/diskcache_manager.py:214–304  ·  view source on GitHub ↗
(result_key, progress_key, user_callback_args, context)

Source from the content-addressed store, hash-verified

212def _make_job_fn(fn, cache, progress):
213 # pylint: disable-next=too-many-statements
214 def job_fn(result_key, progress_key, user_callback_args, context):
215 def _set_progress(progress_value):
216 if not isinstance(progress_value, (list, tuple)):
217 progress_value = [progress_value]
218
219 cache.set(progress_key, progress_value)
220
221 maybe_progress = [_set_progress] if progress else []
222
223 def _set_props(_id, props):
224 cache.set(f"{result_key}-set_props", {_id: props})
225
226 ctx = copy_context()
227
228 def run():
229 c = AttributeDict(**context)
230 c.ignore_register_page = False
231 c.updated_props = ProxySetProps(_set_props)
232 context_value.set(c)
233 errored = False
234 user_callback_output = None # initialized to prevent type checker warnings
235 try:
236 if isinstance(user_callback_args, dict):
237 user_callback_output = fn(*maybe_progress, **user_callback_args)
238 elif isinstance(user_callback_args, (list, tuple)):
239 user_callback_output = fn(*maybe_progress, *user_callback_args)
240 else:
241 user_callback_output = fn(*maybe_progress, user_callback_args)
242 except PreventUpdate:
243 errored = True
244 cache.set(result_key, {"_dash_no_update": "_dash_no_update"})
245 except Exception as err: # pylint: disable=broad-except
246 errored = True
247 cache.set(
248 result_key,
249 {
250 "background_callback_error": {
251 "msg": str(err),
252 "tb": traceback.format_exc(),
253 }
254 },
255 )
256
257 if not errored:
258 cache.set(result_key, user_callback_output)
259
260 async def async_run():
261 c = AttributeDict(**context)
262 c.ignore_register_page = False
263 c.updated_props = ProxySetProps(_set_props)
264 context_value.set(c)
265 errored = False
266 try:
267 if isinstance(user_callback_args, dict):
268 user_callback_output = await fn(
269 *maybe_progress, **user_callback_args
270 )
271 elif isinstance(user_callback_args, (list, tuple)):

Callers

nothing calls this directly

Calls 2

funcFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…