plotly / plotly/dash

[BUG] Long callbacks create processes

Open
#3,177 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Thank you so much for helping improve the quality of Dash!

We do our best to catch bugs during the release process, but we rely on your help to find the ones that slip through.

Describe your context
Please provide us your environment, so we can easily reproduce the issue.

  • replace the result of pip list | grep dash below
dash                 2.18.2
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table           5.0.0
  • if frontend related, tell us your Browser, Version and OS

    • OS: Win 10
    • Browser Edge

Describe the bug

This basic code inspired from the documentation fails:

import time
from dash import Dash, html, Output, Input
from dash.long_callback import DiskcacheLongCallbackManager
import diskcache

cache = diskcache.Cache("./cache")
long_callback_manager = DiskcacheLongCallbackManager(cache)

app = Dash()

app.layout = html.Div([
    html.Div([
        html.P(id="paragraph_id", children=["Button not clicked"]),
        html.Progress(id="progress_bar"),
    ]),
    html.Button(id='button_id', children="Run Job!")
])

@app.callback(
    output=[Output("paragraph_id", "children")],
    inputs=[Input("button_id", "n_clicks")],
    progress=[Output("progress_bar", ("value", "max"))],
    prevent_initial_call=True,
    background=True,
    manager=long_callback_manager
)
def callback(set_progress, n_clicks):
    total = 10
    for i in range(total):
        time.sleep(0.5)
        set_progress((str(i + 1), str(total)))

    return [f"Clicked {n_clicks} times"]

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

with this error:

NameError: name 'time' is not defined

It seems that Dash creates a new python process in the background to execute the long callback without importing all the packages.

Expected behavior

Dash should handle long callbacks with threading or other mechanisms to avoid these issues, or explain in the documentation how to overcome them.

Screenshots

If applicable, add screenshots or screen recording to help explain your problem.

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

Start by reproducing the provided Dash example with DiskcacheLongCallbackManager and the callback that calls time.sleep and set_progress. Trace how the background callback process is started and how imports are made available; done means the example runs without the reported NameError or the required import behavior is clearly documented.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.