Replies: 1 comment 9 replies
-
|
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've built a flask app following the official tutorial and am not seeing persistence with respect to the g object. I'm attempting to persist a single Postgres connection in g.db, but the connection is being recreated on every request. All roads that I've traveled in this regard suggest that I'm using the object per design.
Here's my db.py file:
As you'll notice, I've added some debug print statements to determine what's going on, and I've reduced the choices for DB_CONFIG as they are irrelevant. This particular function is being called via Javascript's fetch function rather than through browser navigation (which shouldn't matter AFAIK). When using this code, I get the following output each time I call the check view:
So according to this output it appears that g is not persisting. I've thought about the potential thread locality of g, but I can run the code as many times as I want, greatly exceeding the number of workers, and still get the same output.
Any advice is greatly appreciated.
Flask ver: 2.0.3
Python ver: 3.9.7
Beta Was this translation helpful? Give feedback.
All reactions