[Flask] global app state

DC at mail.python.org DC at mail.python.org
Fri Apr 28 16:27:46 EDT 2017


Hi, I'm a rather experienced developer but not so much with Python and 
for sure not with Flask. I looked around before posting but I think I 
couldn't find the exact case I'm dealing with.

I want to use Flask to build a backend for a single page web app. The 
backend will be mainly an Oracle connection layer. Because of how the 
application is intended to work, I need cursors to be kept open and 
fetched partially on each request from the web frontend. I plan to 
manually handle connection pooling, web browser <-> server- side cursors 
assignment and timeouts to clear "abandoned" cursors. I know this does 
not follow the typical modern stateless approach, but let's say that I 
have my reasons :)

I plan to use apache or a standalone wsgi container for deployment in 
production. Now... for this to be possible I need to have a common place 
to store an object with all my db connections and open cursors. It must 
be accessible by any worker/thread/process (I can handle concurrency 
manually if needed), and shouldn't be killed just because one client 
finished its request or a worker is not necessary anymore and is terminated.

One way is to have a custom external process and some ipc with a 
stateless Flask app, but it's an additional complication. Is there a way 
with Flask? I guess it's probably impossible if I have different apache 
processes, but what if I force mod_wsgi to only use multithreading?

Thanks


More information about the Flask mailing list