Skip to content

[BUG] Long callbacks create processes #3177

Open
@Mark531

Description

@Mark531

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething brokendocumentationwritten for humans

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions