我使用while 1循环读取数据库的一个表内容,当内容改变时,无法实时改变,求大神帮我看下代码
import MySQLdb
import serial
import time
ser = serial.Serial('/dev/ttyACM0',9600,timeout=1)
conn=MySQLdb.connect(host="192.168.191.5",user="root",passwd="123456",db="test")
cursor = conn.cursor()
try:
while 1:
time.sleep(1.5)
n = cursor.execute("select state from t_led")
r = cursor.fetchone()
p = r[0]
ser.write(p)
a = ser.readline()
print r
except KeyboardInterrupt:
conn.close()
ser.close()
cursor.close()