MySQLdb python 刷新数据库问题
我写了一个Python守护进程来读取数据库...我做了下一步:
db.connect('localhost', user, pass, database)
while true:
cursor = db.cursor()
sql = "SELECT id FROM task WHERE status='pending'"
r = cursor.execute(sql)
if r != 0:
result = cursor.fetchall()
#.....
问题是:当更改数据库时,守护进程检测不到它...可以刷新... 我能做些什么??
谢谢!!
I have wrote a python daemon for read a database... I do the next:
db.connect('localhost', user, pass, database)
while true:
cursor = db.cursor()
sql = "SELECT id FROM task WHERE status='pending'"
r = cursor.execute(sql)
if r != 0:
result = cursor.fetchall()
#.....
The problem is that: when change database, the daemon not detect it... can refresh...
what can I do??
thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这只是一个猜测,因为我没有完整的代码视图,但由于您在循环外部连接,对
database
的任何更改都不会告诉db
重新连接。再次只是猜测,不确定您是否正在线程化,更改如何与守护进程一致......等等
This is just a guess since I don't have a full view of your code, but since you're connecting outside the loop any changes to
database
won't telldb
to reconnect.Again just a guess, not sure if you're threading or not threading, how the change coincides with the daemon... etc
我已经解决了在脚本末尾激活提交的问题:
感谢所有朋友
I have soluted it activating commit at the end of the script:
thanks for all friends