python - Zombie Connection in SQLAlchemy -
dbsession = sessionmaker(bind=self.engine) def add_person(name): s = dbsession() s.add(person(name=name)) s.commit()
everytime run add_person() connection created postgresql db. looking at:
select count(*) pg_stat_activity;
i see count going up, until remaining connection slots reserved non-replication superuser connections
error.
how kill connections? wrong in opening new session everytime want add person record?
in general, should keep session
object (here dbsession
) separate functions make changes database. in case might try instead:
dbsession = sessionmaker(bind=self.engine) session = dbsession() # create session outside of functions modify database def add_person(name): session.add(person(name=name)) session.commit()
now not new connections every time add person database.
Comments
Post a Comment