Python: MySQL: Handling timeouts

后端 未结 3 1396
小鲜肉
小鲜肉 2021-01-13 09:02

I am using Python and mySQL, and there is a long lag between queries. As a result, I get an \'MySQL connection has gone away\' error, that is wait_timeout is exceeded.

3条回答
  •  广开言路
    2021-01-13 09:45

    I had the same problem and wanted to wrap the exception to capture it but instead I solved it by using the following. Before calling the execute, call
    self.con.ping(TRUE)

    http://www.neotitans.com/resources/python/mysql-python-connection-error-2006.html http://mysql-python.sourceforge.net/MySQLdb.html

    I can no longer find the original source material I found this out from, but this solved the problem immediately.

提交回复
热议问题