Requests.get() in dash threaded issue

Hello community,

I’m running a Dash app embedded in flask server using this line :

app = dash.Dash(__name__,,suppress_callback_exceptions=True,server=app_flask)

I have multiple callbacks in separates which uses http requests in parralel with differents urls, :

File1

    @app.callback(Output('myoutput_id','myoutput'),Input('url_id','href'))
    def createDf1(url):
        data1 = requests.get(url)
        # then here I use my data to create a specific dataframe and return it

File2

    @app.callback(Output('myoutput2_id','myoutput'),Input('url2_id','href'))
    def createDf2(url2):
        data2 = requests.get(url2)
        # then here I use my data to create a specific dataframe and return it
        

I read that now the default behavior of dash is with the threaded = true …

My problem is when I make more than 3 or 4 get requests based on the previous example I see that the thread which was launched by the first callback return the value of the second requests.get() or the third one randomly.

Is there a way to make sure that the requests.get result match with the callback sender ?

I really hope that someone could help me :innocent:

Thank’s

I’m not sure if I fully understand what you’re trying to do, but… I ran into a similar issue where the responses from the server were getting mixed up. A client would make a request and receive a response that was intended for another client. Are you caching your responses? For me, I was able to resolve the mixed responses by using Flask-Session.

1 Like

Yes , I’m already using Flask Session .

Actually the problem was from the endpoint which was not able to manage simultaneous calls.

Thank you for yout answer it will helps others who have similar issues