Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django transaction.commit#u手动导致';MySQL服务器已经消失了';_Python_Mysql_Django_Python 2.7_Transactions - Fatal编程技术网

Python django transaction.commit#u手动导致';MySQL服务器已经消失了';

Python django transaction.commit#u手动导致';MySQL服务器已经消失了';,python,mysql,django,python-2.7,transactions,Python,Mysql,Django,Python 2.7,Transactions,有一个长期运行的过程,工作良好。在添加transaction.commit()后开始出现(2006年“MySQL服务器已消失”)错误,我在其中手动提交了事务 之前(效果很好): 之后:(夜间空闲8小时无需处理后获取错误) 注意:我需要像这样刷新它以避免得到过时的数据 flush_transaction() DBObject.objects.get(id = 1) 在哪里 据我所知,我正在切换到手动提交,但似乎我也失去了django的自动重新连接 除了在mysql端增加等待超时之外,还有什么好办

有一个长期运行的过程,工作良好。在添加transaction.commit()后开始出现(2006年“MySQL服务器已消失”)错误,我在其中手动提交了事务

之前(效果很好):

之后:(夜间空闲8小时无需处理后获取错误)

注意:我需要像这样刷新它以避免得到过时的数据

flush_transaction()
DBObject.objects.get(id = 1)
在哪里

据我所知,我正在切换到手动提交,但似乎我也失去了django的自动重新连接


除了在mysql端增加等待超时之外,还有什么好办法来处理这个问题吗?

问题在于切换到提交手动模式。似乎没有正确关闭连接。阅读更多关于

解决此问题的方法是手动关闭数据库连接并重试查询

手动关闭我使用的连接

from django import db
db.close_connection()
希望这有帮助

@transaction.commit_manually
def flush_transaction():
    """
    Flush the current transaction so we don't read stale data

    Use in long running processes to make sure fresh data is read from
    the database.  This is a problem with MySQL and the default
    transaction mode.  You can fix it by setting
    "transaction-isolation = READ-COMMITTED" in my.cnf or by calling
    this function at the appropriate moment
    """
    transaction.commit()
from django import db
db.close_connection()