如果在连接超时范围内,网络恢复 则程序继续跑,如果网络断开时间超过超时设置,程序就报错

import MySQLdb
from datetime import datetime
import cx_Oracle
import os
import sys
import re
import time
reload(sys)
sys.setdefaultencoding('utf-8')
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
conn = cx_Oracle.connect('system/oracle@10.10.17.200/serv')
cur = conn.cursor()
while True:
    cur.execute("select 1 from dual")
    result = cur.fetchall()
    print result
    time.sleep(1)
    

[(1,)]
[(1,)]
[(1,)]
[(1,)]
[(1,)]
[(1,)]
[(1,)]
[(1,)]
[(1,)]
Traceback (most recent call last):
  File "C:/Users/tlcb/PycharmProjects/untitled/rizhiyi/t8.py", line 14, in <module>
    cur.execute("select 1 from dual")
cx_Oracle.OperationalError: ORA-03113: 通信通道的文件结尾
进程 ID: 4340
会话 ID: 10 序列号: 27

Process finished with exit code 1

如果在连接超时范围内,网络恢复 则程序继续跑,如果网络断开时间超过超时设置,程序就报错
原文地址:https://www.cnblogs.com/hzcya1995/p/13349124.html