SQLAlchemy version 0.7.1 MySQL Ver 14.12 Distrib 5.0.77 We have a series of tables with one to many connections: A -> B -> C -> D->E etc.
Script1 has a big for loop over several hundred/thousand values. In each loop iteration it goes through A,B,C, makes some new entries, then calls Function1 (passing some ids from A,B,C). Function1 makes a new entry in D, then calls Function2 (passing ids from A,B,C,D). Function2 makes modification to the entry in D and makes several new entries in E. Not far into the loop we get an error saying the MySQL database has run out of connections: (Operational Error) (1040, 'Too many connections') I suspect this is due to me mishandling sessions, and I've included the likely relevant snippets of code below. Am I doing something obviously incorrect? The goal in the near future is to have Function1 submit Function2 as a job to a cluster with PBS, so Function2 needs to independently access the database. Thanks! In Script1: from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker import database_classes as dc database_url = .... engine = create_engine(database_url, echo=False) dc.Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) .... for fname in dirList: session = Session() .... Function1(database_url,....) In Function1: from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker import database_classes as dc engine = create_engine(database_url, echo=False) Session = sessionmaker(bind=engine) session = Session() ..... Function2(database_url, ....) .... session.close() In Function2: from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker import database_classes as dc engine = create_engine(database_url, echo=False) Session = sessionmaker(bind=engine) session = Session() .... session.close() Database classes: https://github.com/jeffalstott/research_code/blob/master/database_classes.py Script1: https://github.com/jeffalstott/research_code/blob/master/MRC_avalanche_analyses.py Functions: https://github.com/jeffalstott/research_code/blob/master/criticality.py Function1 is "avalanche_analyses" Function2 is "avalanche_statistics" -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.