Long Callback Issue: PID no longer exists

I am seeing issues with the app.long_callback() functionality inside a modal, upon cancelling the callback.

For clarity, if I allow the callback to complete, there is no issue with the callback and the behaviour is as desired. However, if the long_callback is cancelled within execution, I receive the error below, with various process identifiers:

psutil.NoSuchProcess: process PID not found (pid=4208)

How can I negate this? I have used a try, except block in an attempt to catch the error and raise PreventUpdate, but this error shows up in the debugger.

Minimum replicable error (inside a modal) below:

run_button = dbc.Button("Run", color='danger', id="execute-button")
cancel_button = dbc.Button("Cancel", color='danger', id="cancel-button")



output_display_card = dbc.Card(id='calculate-modal-body-population')


@app.long_callback(
    output=Output('calculate-modal-body-population', "children"),
    inputs=[Input("execute-button", "n_clicks")],
    running=[
        (Output("execute-button", "disabled"), True, False),
        (Output("cancel-button", "disabled"), False, True),
    ],
    cancel=[Input("cancel-button", "n_clicks")],
)
def callback(n_clicks):
    try:
        if n_clicks:
            time.sleep(10)
            outcome = html.Div(children=[
                dbc.CardHeader(html.H5("Output Display", className="card-title")),
                dbc.CardBody(dbc.Row(children=[dbc.Col(f"Clicked {n_clicks} times")])),
            ])
            return outcome
        else:
            return None
    except Exception as e:
        print(e)
        raise PreventUpdate

Hello @d_dash_user,

It is now recommended to use background_callback instead of long_callback.

This may or may not fix your issue.