Using Background Callbacks & running on waitress

Dear all,

Hi, I am new to dash.

I’m having some issues with dash & waitress.

I have already studied some documents of dash, but some issues happened.

When I use a normal callback and run it on a WSGI server - waitress, it perfectly works.

But when I use Background Callbacks / Long Callbacks running on waitress, it didn’t respond at all.

OS: windows 10

python: ver 3.9

dash: ver 2.6.0

code:

I’m using Example 4: Progress Bar for testing.

so bg_callback.py:

import time
import os
import dash
from dash import DiskcacheManager, CeleryManager, Input, Output, html

import diskcache
cache = diskcache.Cache(“./cache”)
background_callback_manager = DiskcacheManager(cache)

app = dash.Dash(
name, background_callback_manager=background_callback_manager)
server = app.server
app.layout = html.Div(
[
html.Div(
[
html.P(id=“paragraph_id”, children=[“Button not clicked”]),
html.Progress(id=“progress_bar”, value=“0”),
]
),
html.Button(id=“button_id”, children=“Run Job!”),
html.Button(id=“cancel_button_id”, children=“Cancel Running Job!”),
]
)

@dash.callback(
output=Output(“paragraph_id”, “children”),
inputs=Input(“button_id”, “n_clicks”),
background=True,
running=[
(Output(“button_id”, “disabled”), True, False),
(Output(“cancel_button_id”, “disabled”), False, True),
(
Output(“paragraph_id”, “style”),
{“visibility”: “hidden”},
{“visibility”: “visible”},
),
(
Output(“progress_bar”, “style”),
{“visibility”: “visible”},
{“visibility”: “hidden”},
),
],
cancel=Input(“cancel_button_id”, “n_clicks”),
progress=[Output(“progress_bar”, “value”), Output(“progress_bar”, “max”)],
prevent_initial_call=True
)
def update_progress(set_progress, n_clicks):
total = 5
for i in range(total + 1):
set_progress((str(i), str(total)))
time.sleep(1)

return f"Clicked {n_clicks} times"

if name == “main”:
app.run_server(debug=True)

and wsgi.py:

from waitress import serve
from bg_callback import app
import logging
logger = logging.getLogger(‘waitress’)
logger.setLevel(logging.INFO)

serve(
app.server,
port=8894,
)

Any ideas on how I could fix this?

Thanks in advance for your help!