guys.I need some help.Days ago,I deployed my web project on our server,everything worked well.But next morning I loged the page,and I got an error "Mysql server has gone away...",then I checked the reasons.I found it caused by that the conf of Msyql "wait_timeout=2880000" and "interactive_timeout = 2880000",I also got some solutions like "set pool_recycle=7200 when create_engine" but it doesn't work.I continue searching the ways to it.Someones says 'we must execute session.close() when after use if'.I was going to try it,but there is another error came to me.I used sqlalchemy.orm.relation, there is many_to_many relation between class User and Role.Now I add DBSession.close() like
@classmethod
def get_by_id(cls, id):
user_ = DBSession.query(cls).get(id)
DBSession.close()
return user_
But now when I did this
user = User.get_by_id(1)
user.roles
ERROR:Parent instance <User at 0xace51cc> is not bound to a Session;
lazy load operation of attribute 'roles' cannot proceed
So How can I solve my problem.Much appreciate!