According to the answer given in Is it safe to store per-request data on flask.request? it seems that the g
object is request-local (= has the lifetime of a single request). Maybe I misunderstood this answer, but the Flask documentation states that the g
object would be global which seems to contradict this answer.
The documentation itself is a bit short about these details, so please would you mind to explain the details to the contexts and the global object g
? Specifically to address the following questions:
- In order to store data for the lifetime of a single request, how should that be done? (Using the
request
object, theg
object or which kind of object?) - In order to store data for the lifetime of an application, how should that be done? (Using the
app
object, theg
object or which kind of object?) - Flask could be used in a multi-process environment. Is it correct to assume that in such a mode of operation there will be multiple application-wide objects? (This would imply that all of these
app
org
objects then need to be initialized individually for the lifetime of each worker process.) - Related to question 3: If I require an application wide, single singleton-like object that provides services to a Flask web application, it is mandatory to factor out this service into an external process? (Within a multi-process mode of operation there won't be a single singleton-like instance?)