Hi,
trying to be careful to close all sessions when I'm done with them, I
find myself doing this all the time:
session = Session()
try:
do_stuff_with(session)
finally:
session.close()
This would be neater:
with Session() as session:
do_stuff_with(session)
but the sessionmaker-produced class does not implement the context
manager protocol (the __enter__ and __exit__ methods) used by the with
statement. Now, I can add on the context manager protocol using
contextlib:
from contextlib import closing
with closing(Session()) as session:
do_stuff_with(session)
but is there any reason for the session itself not to support the
context manager protocol and save me the extra closing()?
Regards,
- Gulli
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---