Get new result in infinite loop with SqlAlchemy
Question: I'm new to Python - coming from PHP - and have been bouncing back and forth
between Python official documentation and SqlAlchemy (which I'm trying to use
as easily as Laravel's DB class)

I have this bit of code:

    
    
    from sqlalchemy import *
    engine = create_engine('mysql://root:pass==@aws.com/db')
    db_connection = engine.connect()
    meta = MetaData()
    video_processing = Table('video_processing', meta, autoload=True, autoload_with=engine)
    
    while True:
        sleep(1)
        stmt = select([video_processing]).where(video_processing.c.finished_processing ==  0).where(video_processing.c.in_progress == 0)
    
        result = db_connection.execute(stmt)
    
        rows = result.fetchall()
    
    
        print len(rows)
    
        stmt = None
        result = None
        rows = None
    

When I execute my statement, I let it run and print out the number of rows
that it fetches. While that's going, I go in and delete rows from my db. The
problem is that even though I'm resetting pretty much everything I can think
of that is related to the query, it's still printing out the same number of
fetched rows in every iteration of my loop, even though I'm changing the
underlying data. Any ideas?


Answer: The tricky part is that the connection needs to be closed if using
engine.connect() with db_connection.close() otherwise you might not see new
data changes.

I ended up bypassing the connection and executing my statement directly on the
engine, which makes more sense logically anyways:

    
    
    result = engine.execute(stmt)
    

