On Google Cloud, I'm running an instance of Compute Engine to monitor changes in a table that's on a SQL instance. As per this thread: How to execute Python function when value in SQL table changes?
I made a loop.
My code is:
from sqlalchemy import create_engine
import pandas as pd
un_cloud="xxx"
pw_cloud="xxx"
ip_cloud="xxx"
db_n_cloud="xxx"
engine_input="mysql+pymysql://"+un_cloud+":"+pw_cloud+"@"+ip_cloud+":3306/"+db_n_cloud
engine = create_engine(engine_input)
con_cloud_local = engine.connect()
base=0
while True:
table=pd.read_sql_table('xxx', con=con_cloud_local)
if table.shape[0]>base:
base=table.shape[0]
print(base)
As time progresses the printouts are taking more and more to appear and even at the beginning they are over a second apart. (when it's running for a few minutes, I'm getting to 20s between printouts). That's horrible. I'm looking to get updates close to real-time (<1s).