Long running prodigy database instance throws peewee.InterfaceError: connection already closed

Hi Prodigy Team,

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?

Note: we use Postgres as our database

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.

Hi Ines. Ahh okay, so this kind of error is expected if we keep the prodigy database object reference for a long period.

Okay, I'll try to use the connect helper function every time a query is needed.

Thank you for the answer :slight_smile: