Reputation: 571
I'm building a small webapp using flask and hosted on PythonAnywhere. The app is made of an Exchange
class where several Team
classes interact. Each user who logins is related to a specific Team
. The app will have no more than 30 connected users at the same time although they will have to get info in real time. There is also an always-on task which will also need to connect to the database.
I'm using sqlalchemy
to manage the database connections but I'm constantly getting either (2006, 'MySQL server has gone away')
or (2013, 'Lost connection to MySQL server during query')
. Therefore I was wondering how I should manage concurrent connections within the app. I tried several configurations such as opening and closing the connections after every call in the flask app or even within every class method but nothing seems to work.
Should I make calls the database only from the flask app using for instance flask-sqlalchemy
or are there other ways to achieve this?
Upvotes: 0
Views: 193
Reputation: 5776
Your connections are timing out. Tell sqlalchemy to recycle connections after a time that is shorter than the timeout. Like this:
engine = create_engine('mysql+mysqldb://...', pool_recycle=280)
Upvotes: 0