找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2039|回复: 2

[求助] 异常后如何继续执行

1

主题

1

帖子

1

积分

贫民

积分
1
davidliu 发表于 2019-5-13 23:12:30 | 显示全部楼层 |阅读模式
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并没用,如果其中一台机器连不上,程序就中止执行了,如何不中止,继续往下执行?
回复

使用道具 举报

3

主题

278

帖子

278

积分

侠客

积分
278

热心会员

uitb 发表于 2019-5-14 11:34:49 | 显示全部楼层
else:
          break

这一句,执行一条没问题的话,就跳出循环停止继续执行了
回复 支持 反对

使用道具 举报

1

主题

10

帖子

10

积分

贫民

积分
10
qingchunshengge 发表于 2019-5-27 12:59:05 来自手机 | 显示全部楼层
可以使用多线程
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表