|
a.txt存放的是多个机器IP,其中一台的MYSQL连不上,如何让后面的机器继续执行
import sys
import pymysql
def execsql():
file = open('a.txt','r')
try:
while True:
connstr = file.readline()
if connstr:
struser = "abc"
strpwd = "abc"
db = pymysql.connect(connstr,struser,strpwd,"mysql")
cursor = db.cursor()
strsql = """
select count(*) from user
"""
try:
cursor.execute(strsql)
aaa = cursor.fetchone()
print(aaa)
db.close()
except Exception as e:
print("Error",str(e))
cotinue
else:
break
finally:
file.close()
if __name__ == '__main__':
execsql()
上述CONTINUE并没用,如果其中一台机器连不上,程序就中止执行了,如何不中止,继续往下执行?
|
|