while True:
task = TaskQueue.query.filter_by(status=0).order_by(TaskQueue.create_time.asc()).first()
print(task)
if task:
pass
else:
time.sleep(5)
数据表中记录的 status 全部为 0,运行以上代码 持续输出 None ,不中断进程,手动修改数据表中一条记录status=1 以上代码还是照常输出 None 相当于task还是未获取到值,求解?
大家讲道理2017-04-18 09:17:53
I know how to solve it, but I don’t know the reason. Just add db.session.remove() when Task = None~~
高洛峰2017-04-18 09:17:53
I have never used flask_sqlalchemy. According to your idea, sql should be like this. Find the first status=0 in ascending order by creation time
select * from taskqueue where status=0 order by create_time asc limit 0, 1
Theoretically, if the status in your data table is all 0, there should be data every time. The problem may be that your ORM is not connected to the specified library, or the first function does not work.
tasks = TaskQueue.query.filter_by(status=0)
print len(tasks)