Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Long callbacks create processes #3177

Open
Mark531 opened this issue Feb 21, 2025 · 0 comments
Open

[BUG] Long callbacks create processes #3177

Mark531 opened this issue Feb 21, 2025 · 0 comments
Labels
bug something broken documentation written for humans P3 backlog

Comments

@Mark531
Copy link

Mark531 commented Feb 21, 2025

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.

@gvwilson gvwilson added bug something broken P3 backlog documentation written for humans labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken documentation written for humans P3 backlog
Projects
None yet
Development

No branches or pull requests

2 participants