How to share in memory resources between Flask methods when deploying with Gunicorn : <p>I have implemented a simple microservice using Flask, where the method that handles the request calculates a response based on the request data and a rather large datastructure loaded into memory. 
Now, when I deploy this application using gunicorn and a large number of worker threads, I would simply like to share the datastructure between the request handlers of all workers. Since the data is only read, there is no need for locking or similar. What is the best way to do this?</p>

<p>Essentially what would be needed is this:</p>

<ul>
<li>load/create the large data structure when the server is initialized</li>
<li>somehow get a handle inside the request handling method to access the data structure</li>
</ul>

<p>As far as I understand gunicorn allows me to implement various hook functions, e.g. for the time the server gets initialized, but a flask request handler method does not know anything about the gunicorn server data structure. </p>

<p>I do not want to use something like redis or a database system for this, since all data is in a datastructure that needs to be loaded in memory and no deserialization must be involved.</p>

<p>The calculation carried out for each request which uses the large data structure can be lengthy so it must happen concurrently in a truly independent thread or process  for each request (this should scale up by running on a multi-core computer). </p>
