You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I meet something strange in production. I have set setsession=["set autocommit=1"] in PooledDB and think it will be auto commit even if the connection has been reconnect.
But it seems the setsession do not work for pymysql in reconnect situation. Here is my demo.
When the demo run, try to restart mysql server, and after the application reconnects mysql successfully and then get no error return, but, actually, it will not insert to mysql for rest sql. After debug the source code I think the reason it that in this situation it reconnects by pymysql directly not by dbutils.
I add some debug code in SteadyDBConnection to help me understand the process.
def_ping_check(self, ping=1, reconnect=True):
"""Check whether the connection is still alive using ping(). If the the underlying connection is not active and the ping parameter is set accordingly, the connection will be recreated unless the connection is currently inside a transaction. """ifping&self._ping:
try: # if possible, ping the connectionmy_reconnect=Trueprint"try to ping by pymysql(reconnect={0})".format(my_reconnect)
alive=self._con.ping(reconnect=my_reconnect)
# alive = self._con.ping()except (AttributeError, IndexError, TypeError, ValueError):
print"ping method is not available"self._ping=0# ping() is not availablealive=Nonereconnect=FalseexceptException,e :
print"try to ping by pymysql(reconnect={0}) fail".format(my_reconnect)
alive=Falseelse:
ifaliveisNone:
alive=Trueifalive:
reconnect=Falseprint"try to ping by pymysql(reconnect={0}) success".format(my_reconnect)
ifreconnectandnotself._transaction:
try: # try to reopen the connectionprint"try to reconnect by dbutils"con=self._create()
exceptException:
print"try to reconnect by dbutils fail"passelse:
print"try to reconnect by dbutils success"self._close()
self._store(con)
alive=Truereturnalive
For pymysql, its ping method has default reconnect behavior, and the my_reconnect variable addde for debug always will be true. It seems that dbutils assumed ping will not reconnect. So the setsession parameter will not apply to pymysql reconnect situation. Should setsession used in this way? Is it possible to add compatible parameter for driver which has reconnect parameter in its ping method?
Actually, I found another way to solve my promble by adding autocommit in db_con, like
I meet something strange in production. I have set setsession=["set autocommit=1"] in PooledDB and think it will be auto commit even if the connection has been reconnect.
But it seems the setsession do not work for pymysql in reconnect situation. Here is my demo.
When the demo run, try to restart mysql server, and after the application reconnects mysql successfully and then get no error return, but, actually, it will not insert to mysql for rest sql. After debug the source code I think the reason it that in this situation it reconnects by pymysql directly not by dbutils.
I add some debug code in SteadyDBConnection to help me understand the process.
For pymysql, its ping method has default reconnect behavior, and the my_reconnect variable addde for debug always will be true. It seems that dbutils assumed ping will not reconnect. So the setsession parameter will not apply to pymysql reconnect situation. Should setsession used in this way? Is it possible to add compatible parameter for driver which has reconnect parameter in its ping method?
Actually, I found another way to solve my promble by adding autocommit in db_con, like
My local python and package version:
dbutils : 1.1
pymysql : 0.9.3
Python : 2.7.13
The text was updated successfully, but these errors were encountered: