Repeating an app.callback only when it finishes (expensive task of varying length)

Dear Forum,

my problem is that i have a computationally expensive callback whos computation time varies on each iteration (a minimize function that ranges from 5 to 12 seconds with ocassional 30 second outliers).

Therefore, i cant use the interval component to refire every n seconds as variables in the already running callback seem to be saved causing computations to fail on the next iterration.

using the same output as input is not possible either.

What i have tried using a second dummy function in order to achieve dash switching back and forth between callbacks after the start button is clicked

A simpliefied illustration of the problem:

Start code!

app.layout contains:



Output(‘invoke-update’, ‘data’),
Input(‘start’, ‘n_clicks_timestamp’),
Input(“invoke-update2”, “data”),
], prevent_initial_call=True
def invokeupdate(start, invoke):

if start>0:
    dummyval=np.random.randint(0, 10000, size=1)
    return dummyval
    raise dash.exceptions.PreventUpdate    

Output(“invoke-update2”, “data”),
Input(‘invoke-update’, ‘data’),
def updateData(invokeupdate):

time.sleep(10) #this illustrates the expensive task that varies in time
dummyval2=np.random.randint(0, 10000, size=1)
return dummyval2

End Code!

KeyError: “Callback function not found for output ‘……interval-component.disabled…’, perhaps you forgot to prepend the ‘@’?”

I had an interval component in the code previously but deleted it so its confuses me that this error message comes up…

I am thankful for any help. I also apologize for not pasting code segments in the right format, i am thankful for a tip on how to do this in the plotly forum.

Kind regards,