Access variables without re-loading them between management commands in Django
I know there isn't a 'proper' solution to this. I used a crude approach of writing a temp file after having these models loaded in the \schema.py and then import the object model into my 'business_logic.py' checking if the file is there, then don't initialize the model again.
Hope it helps others.
We are building an AI enabled web application that uses huge memory models that ideally should be loaded only once in memory as global variables.
These variables are to be used by different management commands which run as individual processes and make use of the Django framework. And of course, the runserver command too accesses these global variables.
These models are loaded inside a single module commons but since we are spawning different processes, let us assume two for now - runserver and process_tasks, these models are essentially loaded twice in memory via the commons module.
Is there a way to load these models centrally and share the variables between independently spawned processes. I'm aware of the multiprocessing module in python and the Manager API, but can't figure out a way for incorporating it with the current scenario.
Is there a way to run a standalone python process that holds these variables and be able to access them from multiple other processes?