Hello there, I have the following code structure (more or less) in several processes:
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker engine = create_engine(some_mysql_dburi) session = sessionmaker(bind=engine)() while True: query = session.query(...).filter(...) # do something here from that query, update, insert new rows, etc. session.commit() I am getting a too many connections error and it's not all the time, so I'm not sure what would it be. Although there are several processes running, I don't think at some time I'm connected to mysql server more than the amount of connections allowed, which by default it's about 150 connections I think, and I'm not modifying the default value. So I must have some errors in this layout of my code. Here are some of the questions about the session and the connection(s) within I'd like to ask: 1- How many opened connections are maintained by a single session object? I read somewhere it's only one, but, here it's my next 2- Does the session close the connection being used or requests for another? If it requests for a new one, does it close the previous (i.e., return it to the engine pool)? 3- Should I call session.close() right after the session.commit() statement? If have to, do I have to put the session creation inside the while? I read that when the session gets garbage collected the connection(s) is(are) closed, so I could do this, but I don't know if it is a good use of the session. I read the docs many times and I didn't find anything solid that answers that questions to me, any help on the subject will be very appreciated, thanks in advance. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.