Initializing a very large library once per user

Hi All,

I’ve been having a great time developing with Dash but have run into a performance issue.

One project I’ve been working on requires the initialization of a large library. I only need one function from the library which runs very fast once the library has been initialized.

I wish I could pair back the library but unfortunately its proprietary. My hands are tied on this and I have to use it.

As of now I initialize the library on each callback to keep each user session separated. Is there a way to initialize a library once per user session however?

for a more concrete example of what I’m talking about, current code:

import NNT

@app.callback(stuff..)

def update_function(inputs):
    #this takes forever:
    usrfn = NNT.initialize()
    return usrfn.NNT(inputs)

Ideal idea of code:

import NNT

@app.callback(stuff..)

def update_function(inputs):
    return usrfn.NNT(inputs)

def user_session_created():
     usrfun = NNT.initialize()

Thanks for any help.

Couldn’t you run a command such as:
Import function from library

This should do it.
https://dash.plot.ly/sharing-data-between-callbacks

1 Like