Could Dash execute what's inside a callback in parallel if there are several functions' calls inside?

Hi everyone,

One of my callback calls a page on which there are several tables; it takes 3-4 sec before it is displayed.

The question is: if, instead of calling the full page, I split this page in 4 part, and then call each partial page like this:

@app.callback([Output('section1', 'children'), 
               Output('section2', 'children'), 
               Output('section3', 'children'),
               Output('section4, 'children')],
              [Input('tabs-example', 'value')])
def render_content(tab):
    return section1, section2, section3, section4

Does Dash execute section1(), and wait until it gets its results, prior to executing section2()? In which case the total time would be something like 1sec+1sec+1sec+1sec,
Does dash execute section1(), section2(), section3(), section4() in parallel ? in which case the total waiting time would be defined by the slowest function.

Generally speaking, functions inside a callback might be interdependant, so, I assume that by default Dash execute s each function on a first come first served basis?

I also assume that, if write 4 different callback, each with the same input, but with different output, in this case, they would be executed in parallel, being triggered at the same time ? is it correct?

Every callback is just a regular python function run in a separate thread (or a separate process depending how you launched Dash).

This means you are dealing with regular Python concurrency issues, there’s nothing special about the way Dash works vs. any other Python tool.

If you have 4 long running independent functions that rely on I/O you should run them in separate threads. If you have 4 long running independent calculations that access the GIL (i.e. any Python object) you should probably run them in a separate Process.

1 Like

Ok, makes sense, thanks.

Hi @Damian

Thanks for the explanation.

I am currently hosting my Dash web-app on a Windows 10 VM and wanted to know if I can run 3 different callbacks that rely on 3 different dataframes parallely? The callbacks are fired when the user selects an option from a dropdown menu and update 3 different charts.

Since this process is IO bound with calls made to the Flask Server, I wanted to know whether I can run them in parallel?


I would suggest asking a new question with a dummy example of what you intend if you are having specific problems.

Accessing dataframes in memory is not I/O bound, but I don’t know what you’re doing, you could be reading out of a CSV or a database every time you get the dataframe in which case it is I/O bound.

The main thing is write out a realistic example and see what the performance is like, either it will work within your performance parameters or it won’t and you’ll have to rethink your approach.

Hi Damian,

Thanks for the reply

Here’s my post with a gif and a snippet of my code.

As mentioned, the data processing part of my callbacks gets done under or around 1 second but the display takes time to load on to the webapp. Is this IO or CPU bound?