问题:
python 程序需要不停访问数据库,获取数据进行处理, 但查询结果为空时,如何处理?
关键点:
while 循环 、 continue 退出 循环 、 if not
解决伪代码:
def main(): while True: print(datetime.now(),'INFO : begin ******************************' ) query_sql = 'select xxx' result = exec_query_sql(query_sql) if not result : # 即result是空的时候 print(datetime.now(),'Waring : no query result, sleep 60s' ) time.sleep(60) continue # 退出本次while循环,执行下一次 for res_tuple in result: # do something main()