【发布时间】:2022-01-13 07:52:57
【问题描述】:
我正在尝试运行一个调度程序,我的索引函数将在每 1 分钟内运行。我正在使用烧瓶和 postgresql。但是在运行烧瓶运行之后
app.run() 未执行。这是代码:
def index():
connection = db.engine.connect(close_with_result=True)
print('first')
sql = text("""delete from user""")
print('done')
connection.execute(sql)
connection = db.engine.connect(close_with_result=True)
sql = text("""select * from user where name='a' or name='b'""")
connection.execute(sql)
connection.close()
schedule.every(1).minutes.do(index)
while True:
schedule.run_pending()
time.sleep(1)
# scheduler wait for 1 second
if __name__ == "__main__":
app.run()
但似乎这段代码无法访问:
if __name__ == "__main__":
app.run()
因为这部分代码:
while True:
schedule.run_pending()
time.sleep(1)
# scheduler wait for 1 second
为什么它不起作用?
【问题讨论】:
标签: python postgresql