Following what we commented in How to close sqlalchemy connection in MySQL, I am checking the connections that SQLAlchemy creates into my database and I cannot manage to close them without exiting from Python.
If I run this code in a python console, it keeps the session opened until I exit from python:
from sqlalchemy.orm import sessionmaker
from models import OneTable, get_engine
engine = get_engine(database="mydb")
session = sessionmaker(bind=engine)()
results = session.query(OneTable.company_name).all()
# some work with the data #
session.close()
and the only workaround I found to close it is to call engine.dispose() at the end.
As per the comments in the link I gave above, my question are now:
- Why is
engine.dispose()necessary to close sessions? - Doesn't
session.close()suffice?
sqlalchemy.pool.NullPooldoesn't solve your problem? - Alvaro FuentesAccessShareLockon postgres relations afterselectquery is executed - newbie