plotly / plotly/dash

progress callable of a bg callback sometimes doesn't trigger

Open
#2,828 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

python 3.10.13
dash 2.16.0

  • if frontend related, tell us your Browser, Version and OS

    • OS: macos 14.4
    • Browser firefox
    • Version 124.0.2

Describe the bug

A function callable of a callback with a progress param doesn't seem to get hooked immediately. And calls to this callable seem to be ignored sometimes - especially fraction of a seconds after the callback itself has been triggered.

Expected behavior

MVE:

from dash import html, Input, Output, Dash, callback, DiskcacheManager
import diskcache
import time

cache = diskcache.Cache("./cache")
background_callback_manager = DiskcacheManager(cache)

app = Dash(__name__, background_callback_manager=background_callback_manager)
app.layout = html.Div(
    [html.Div(id="result"), html.Div(id="progress"), html.Button("Run", id="run")]
)


@callback(
    [Output("result", "children")],
    [Input("run", "n_clicks")],
    prevent_initial_call=True,
    background=True,
    running=[(Output("run", "disabled"), True, False)],
    progress=[Output("progress", "children")],
)
def run(set_progress, n):
    # time.sleep(1)
    set_progress("running")
    time.sleep(1)
    set_progress("still running")
    time.sleep(1)  # long running function
    set_progress("finished")
    return (f"Run clicked {n} times",)


if __name__ == "__main__":
    app.run(debug=True)

Run this app and click the button.

Expected behaviour:

  • it shows "running immediately after pressing the button. Then after a second, "still sunning" is shown and after yet another second "finished" is displayed and stays on the screen.

Observed behaviour:

  • after clicking a button, nothing changes for a second, and then it shows "still running". The first call to set_progress at the beginning of the callback seems to be ignored.
  • if you uncomment the time.sleep call, then the first call to set_progress seems to go through.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided MVE using Dash, DiskcacheManager, and the background callback with progress to reproduce the missed initial set_progress call. Start by tracing the background callback and progress handling entry points shown in the example. Done means the initial, intermediate, and final progress values appear reliably, including when no initial sleep is used.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.