I'm using the Peewee ORM in my Python WSGI web app. I've been having issues with the MySQL Server "going away", so I switched to the PooledMySQLDatabase. I will still having issues with the server going away after a few hours..
According to the Docs, for best performance I must manage the connection(s) myself, by calling .connect() and .close(). I was not doing this at all.
I've added 2 decorators that get called before and after every request, but is this correct?
@pre_save()
def pre_save_handler(sender,instance,created):
db.connect()
logger.debug('Attempting to save %s' % instance)
@post_save()
def post_save_handler(sender, instance, created):
db.close()
logger.debug('%s was just saved' % instance)
Are there any pitfalls doing it this way? Should I move the .connect() and .close() into my application?