We have a long-running flask application that opens a prodigy database connection. We encountered a problem, at some point, it throws an error peewee.InterfaceError: connection already closed.
I wonder what is the best practice to manage the database connection. The current setup is that we make a connection once (when the flask app is initialized) with the prodigy connect function and keep the database object reference for the entire application. Is it better to connect and close the database connection only when it is needed?
Hi! I think you might be running into a problem where peewee has already closed the database connection, which it manages under the hood. In theory, it should be fine to use the connect helper every time you need to access the Prodigy DB. If the connection is still open, peewee will use that, otherwise it will reconnect.