Most efficient way to fire a dash callback every n-seconds

Hello,

what do you think it is the most efficient way to fire a call back every n-seconds?

I am running some async computation in the backend and saving the results, and I would like the call back from time to time to check if the results is computed and render some message to the browser.

thanks!

I think the most efficient poll strategy would be to use an interval component with a clientside callback.

Alternatively, you could signal completion from the server using a websocket or event source component, but that requires a bit more setup.

Thanks for your reply!

what do you think about adding in the layout a dcc.Store(id='dum_div')

and use a call back like

@app.callback(
    Output('dum_div','data'),
    Input('dum_div',data),
    )
def refresh(dum_data)):
    # do some stuff
    sleep(5) #wait some seconds
    return ''

would that be really inefficient or slow down the app?

I don’t understand what you are trying to illustrate. Could you provide more context and/or elaborate on what you are trying to do?

I am trying to do some async work (for example sending emails). My hosting provider does not support thread or other similar lib, but it does allow to set some “always-on-task”, so I create a csv file (or database it is the same) with a queue of async jobs to be done with info on the job status (pending, processing, done). the always-on-task run the jobs one by one from eat queue. I want to render at screen if a specific job is done, thus the need to check every n-second the csv file to check the job status.

so in my small example the “do some stuff” would be for example reading the latest info from a csv file.