Skip to content

Commit

Permalink
Remove ignore register page flag when calling background callbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Sep 15, 2022
1 parent 6886670 commit bd0676f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
11 changes: 1 addition & 10 deletions dash/_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,7 @@ def add_context(*args, **kwargs):
job_fn,
func_args if func_args else func_kwargs,
AttributeDict(
args_grouping=callback_ctx.args_grouping,
using_args_grouping=callback_ctx.using_args_grouping,
outputs_grouping=callback_ctx.outputs_grouping,
using_outputs_grouping=callback_ctx.using_outputs_grouping,
inputs_list=callback_ctx.inputs_list,
states_list=callback_ctx.states_list,
outputs_list=callback_ctx.outputs_list,
input_values=callback_ctx.input_values,
state_values=callback_ctx.state_values,
triggered_inputs=callback_ctx.triggered_inputs,
**context_value.get(),
),
)

Expand Down
4 changes: 3 additions & 1 deletion dash/long_callback/managers/celery_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ def _set_progress(progress_value):
ctx = copy_context()

def run():
context_value.set(AttributeDict(**context))
c = AttributeDict(**context)
c.ignore_register_page = False
context_value.set(c)
try:
if isinstance(user_callback_args, dict):
user_callback_output = fn(*maybe_progress, **user_callback_args)
Expand Down
56 changes: 34 additions & 22 deletions dash/long_callback/managers/diskcache_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import traceback
from contextvars import copy_context

from . import BaseLongCallbackManager
from ..._callback_context import context_value
from ..._utils import AttributeDict
from ...exceptions import PreventUpdate

_pending_value = "__$pending__"
Expand Down Expand Up @@ -110,12 +113,13 @@ def make_job_fn(self, fn, progress):
def clear_cache_entry(self, key):
self.handle.delete(key)

# noinspection PyUnresolvedReferences
def call_job_fn(self, key, job_fn, args, context):
# pylint: disable-next=import-outside-toplevel,no-name-in-module,import-error
from multiprocess import Process

# pylint: disable-next=not-callable
proc = Process(target=job_fn, args=(key, self._make_progress_key(key), args))
proc = Process(target=job_fn, args=(key, self._make_progress_key(key), args, context))
proc.start()
return proc.pid

Expand Down Expand Up @@ -147,7 +151,7 @@ def get_result(self, key, job):


def _make_job_fn(fn, cache, progress):
def job_fn(result_key, progress_key, user_callback_args):
def job_fn(result_key, progress_key, user_callback_args, context):
def _set_progress(progress_value):
if not isinstance(progress_value, (list, tuple)):
progress_value = [progress_value]
Expand All @@ -156,27 +160,35 @@ def _set_progress(progress_value):

maybe_progress = [_set_progress] if progress else []

try:
if isinstance(user_callback_args, dict):
user_callback_output = fn(*maybe_progress, **user_callback_args)
elif isinstance(user_callback_args, (list, tuple)):
user_callback_output = fn(*maybe_progress, *user_callback_args)
ctx = copy_context()

def run():
c = AttributeDict(**context)
c.ignore_register_page = False
context_value.set(c)
try:
if isinstance(user_callback_args, dict):
user_callback_output = fn(*maybe_progress, **user_callback_args)
elif isinstance(user_callback_args, (list, tuple)):
user_callback_output = fn(*maybe_progress, *user_callback_args)
else:
user_callback_output = fn(*maybe_progress, user_callback_args)
except PreventUpdate:
cache.set(result_key, {"_dash_no_update": "_dash_no_update"})
except Exception as err: # pylint: disable=broad-except
cache.set(
result_key,
{
"long_callback_error": {
"msg": str(err),
"tb": traceback.format_exc(),
}
},
)
else:
user_callback_output = fn(*maybe_progress, user_callback_args)
except PreventUpdate:
cache.set(result_key, {"_dash_no_update": "_dash_no_update"})
except Exception as err: # pylint: disable=broad-except
cache.set(
result_key,
{
"long_callback_error": {
"msg": str(err),
"tb": traceback.format_exc(),
}
},
)
else:
cache.set(result_key, user_callback_output)
cache.set(result_key, user_callback_output)

ctx.run(run)

return job_fn

Expand Down

0 comments on commit bd0676f

Please sign in to comment.