【发布时间】:2018-07-04 08:02:27
【问题描述】:
我有 2 个 pyton 程序 1) 处理数据库的“Prog1.py” - 从数据库中查询 2) 'Prog2.py' 包含如下的主运行循环
#importing the database class from Prog1.py (mysql.connector used to in Prog1.py)
from database import Database
...
#main run loop
while(True):
time.sleep(0.2)
for loc in data:
self.datafunc(loc)
call_func_fromprg1()
foo()
bar()
#not to run these conditions if exception is met
if expression1:
then operation1
if expression1:
then operation2
if expression3:
then operation3
if expression4:
then operation4
var = time()
我正在尝试在 call_func_fromprg1() 创建一个错误异常,其中调用 Prog1.py 中的函数并引发错误
mysql.connector.errors.InternalError : Deadlock found when try to get lock
并跳过 while 循环的其余部分,最后不更新时间,并在 0.2 秒后重新循环,如代码中给出的那样。
我需要的是写以下子句的最佳位置
try:
...
except:
continue
...
【问题讨论】:
标签: python mysql exception-handling mysql-python