我有一个烧瓶休息API。有一个函数,每分钟重复一次并更新数据库(sqlite3)。它工作了一段时间,但一段时间后API无响应,不会响应请求。我认为这个功能使API无响应。我可以看到问题标题中提到的错误。我在这里做错了吗?任何帮助表示赞赏。
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import threading
app = Flask(__name__)
db = SQLAlchemy(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
.
.
.
def UpdateStatus():
threading.Timer(60, UpdateStatus).start()
messages = Message.query.filter((Message.status != 'Seen')).all()
for msg in messages:
try:
messageid= msg.messageid
wamessageid= msg.wamessageid
timestamp= datetime.now()
result= driver.get_message_status(wamessageid)
if result==1:
status='Sent'
api_response= 'OK: Message sent'
elif result==2:
status= 'Delivered'
api_response= 'OK: Message Delivered'
elif result==3:
status= 'Seen'
api_response= 'OK: Message Seen'
message = Message.query.filter_by(messageid = messageid).first()
if message.status!= status:
message.status= status
message.apiresponse= api_response
if status== 'Delivered':
message.timestamp_delivered= timestamp
if status== 'Seen':
if message.timestamp_delivered is None:
message.timestamp_delivered= timestamp
message.timestamp_seen= timestamp
db.session.commit()
except:
traceback.print_exc()
continue