On Jun 14, 11:19 pm, Michael Bayer <[email protected]> wrote:
> the new SessionTransaction that occurs in close() does not request any
> connection resources, and is discarded immediately along with the session
> that is the subject of remove(). I don't see how it could be affected by
> any previous requests. Each request should have a totally new Session
> object, with a totally new SessionTransaction object. The old one is gone as
> soon as remove() completes.
Here's my example short test case:
import gc
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.orm.session import SessionTransaction
from sqlalchemy.pool import NullPool
engine = create_engine('sqlite://', poolclass=NullPool)
sessions = []
# To simulate multi-db setup, create two sessions
for i in range(2):
sessions.append(scoped_session(sessionmaker(bind=engine)))
for i in range(1, 3):
print 'Looping: iteration (request) #%d' % i
tolist = [c for c in gc.get_objects()
if isinstance(c, SessionTransaction)]
assert len(tolist) == 0
# Apparently scoped_sessions can be used without
# instantiating, so do that
# Just one of the databases will be used in the
# processing
s = sessions[0]
s.execute('select 1')
tolist = [c for c in gc.get_objects()
if isinstance(c, SessionTransaction)]
assert len(tolist) == 1
for s in sessions:
#s.commit() # Not needed, and makes no difference
s.remove()
# There should be no SessionTransactions remaining
tolist = [c for c in gc.get_objects()
if isinstance(c, SessionTransaction)]
# On my system, the next line raises AssertionError
assert len(tolist) == 0, 'No SessionTransactions hanging around'
output:
Looping: iteration (request) #1
Traceback (most recent call last):
File "sqlatest.py", line 35, in <module>
assert len(tolist) == 0, 'No SessionTransactions hanging around'
AssertionError: No SessionTransactions hanging around
BTW I'm using SQLA trunk on Ubuntu Karmic.
Regards,
Vinay Sajip
--
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.