在python中监视MySQLdb中的新条目和Flask [英] Monitor MySQLdb in python for new entries and Flask

查看:82
本文介绍了在python中监视MySQLdb中的新条目和Flask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种不断检查我的数据库(MySQL)中是否有新条目的方法.提交新条目后,我想使用Flask将其输出到网页中. 由于该过程需要时间才能完成,因此我想给用户留下印象,检索数据只用了几秒钟.

I'm looking for a way to constantly check my database (MySQL) for new entries. Once a new entry is committed I want to output it in a webpage using Flask. Since the process takes time to finish I would like to give the users the impression it took only few seconds to retrieve data.

目前,我正在等待整个过程完成,以便为用户提供整个结果.但是,我希望每次将新条目添加到数据库时都更新结果网页.因此,例如,第一个条目被添加到数据库中,用户立即可以在网页上看到它,然后添加第二个条目,用户现在可以在网页上看到第一和第二个条目,依此类推.我不知道它是否必须来自烧瓶或其他方式

For now I'm waiting that the whole process finishes to give to the user the whole result. But I would prefer to update the result web-page every time a new entry was added to the DB. So for example the first entry is added to the DB, immediately the user can see it on the web-page, then a second entry is added the user can now see both the first and the second entries on the web-page and so on. I don't know if it has to come from flask or other ways

有什么主意吗?

推荐答案

您可以将MySQL设置为将所有提交记录到通用查询日志中,并监视所有更改(例如,通过 PyNotify ).文件更改后,您可以解析新的日志条目并获取信号.通过这种方式,您将避免汇集更改.

You can set MySQL to log all commits to General Query Log and monitor all changes (for example via Watchdog or PyNotify). Once the file changes, you can parse the new log entries and get the signal. By this way you'll avoid pooling for changes.

更好的方法当然是在将数据存储到数据库时发送信号.

The better way would be of course send the signal while storing data to the database.

这篇关于在python中监视MySQLdb中的新条目和Flask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆