Python Mysql Connector not getting new content -


i making simple python script checks mysql table every x seconds , print result console. use mysql connector driver.

however, running script prints initalial values. mean, if change values in database while script running, it's not registered script , it's keeps on writing initial values.

the code retrieves values in while loop follows:

def get_fans():     global cnx     query = 'select * config'     while true:         cursor = cnx.cursor()         cursor.execute(query)         (config_name, config_value) in cursor:             print config_name, config_value         print "\n"         cursor.close()         time.sleep(3) 

why happening?

most likely, it's autocommit issue. mysql connector driver documentation states, has autocommit turned off. make sure commit implicit transactions while changing table. because default isolation repeatable read have:

all consistent reads within same transaction read snapshot established first read.

so guess have manage transaction polling script. or change isolation level read committed.

though, better way restore mysql client default autocommit-on mode. though pep 249 guides have disabled, it's mere proposal , serious design mistake. not makes novices wonder uncommited changes, makes read-only workload slower, complicates data-layer design , breaks explicit better implicit python zen. sluggish things django have rethought.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -