开发者

MySQLdb python problem refresh database

I have wrote a python daemon for read a database... I do the next:

db.connect('开发者_JAVA技巧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!!


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 tell db 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:

db.autocommit(True)

thanks for all friends

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜