Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3fb377

Browse files
bramusandrewferlitsch
authored andcommitted
Correctly restore connection if MySQL server has gone away (GoogleCloudPlatform#2421)
1 parent 900900b commit f3fb377

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

functions/sql/mysql_sample.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ def __get_cursor():
4646
PyMySQL does NOT automatically reconnect,
4747
so we must reconnect explicitly using ping()
4848
"""
49-
try:
50-
return mysql_conn.cursor()
51-
except OperationalError:
49+
if not mysql_conn.open:
5250
mysql_conn.ping(reconnect=True)
53-
return mysql_conn.cursor()
51+
return mysql_conn.cursor()
5452

5553

5654
def mysql_demo(request):

0 commit comments

Comments
 (0)