Assuming you are using mysql.connector , the default value for the autocommit property autocommit False, which could cause your script to freeze due to another session that is waiting for completion.
SQLAlchemy uses a BEGIN statement ( START TRANSACTION alias) that forces the session to receive LOCK tables / database, and your connection will wait until the lock is approved.
To overcome this behavior (and because you said you only need to READ the data during the session), you can set autocommit = True when creating the session:
Session = sessionmaker(bind=engine, autocommit=True)
Another option - after creating the session, you can do SET AUTOCOMMIT=1 :
s = Session() s.execute("SET AUTOCOMMIT=0")
You can also try setting the autocommit property directly in the connection string:
engine = create_engine("mysql+mysqlconnector://user:pass@localhost/dbname?autocommit=1")
However, I have not tested it. According to the docs, it should work.
Dekel
source share