python待解决问题笔记

2006, 'MySQL server has gone away'

描述:mysql服务端断开idle过期连接,而客户没有检测重连所以报错。

解决:

def is_connection_usable():
    try:
        connection.connection.ping()
    except:
        return False
    else:
        return True


def do_queue():
    while True:
        if not is_connection_usable():
            connection.close()
        # do long time task

  

原文地址:https://www.cnblogs.com/jcli/p/3575846.html