You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Session is very much intended to be used in a non-concurrent fashion, which usually means in only one thread at a time.
The Session should be used in such a way that one instance exists for a single series of operations within a single transaction. One expedient way to get this effect is by associating a Session with the current thread (see Contextual/Thread-local Sessions for background). Another is to use a pattern where the Session is passed between functions and is otherwise not shared with other threads.
I.e.: instead of passing around an instantiated session, we should pass around a class Session, created by an initial sessionmaker call, and use it in this way:
fromsqlalchemyimportcreate_enginefromsqlalchemy.ormimportsessionmaker# an Engine, which the Session will use for connection# resourcesengine=create_engine('postgresql://scott:tiger@localhost/')
# a sessionmaker(), also in the same scope as the engineSession=sessionmaker(engine)
# we can now construct a Session() and include begin()/commit()/rollback()# at oncewithSession.begin() assession:
session.add(some_object)
session.add(some_other_object)
# commits the transaction, closes the session
(The overall idea, after changing the call, is to use the same "channels" that are currently used to propagate the session object, to propagate instead the Session class)
The text was updated successfully, but these errors were encountered:
From SQLAlchemy:
I.e.: instead of passing around an instantiated
session
, we should pass around a classSession
, created by an initialsessionmaker
call, and use it in this way:This is not that complicated, and essentially it boils down to change this call:
https://github.com/N3PDF/banana/blob/c33d339fb5ce6bc483154a6a5589711d58e7a35b/src/banana/benchmark/runner.py#L209
removing the last call, to get just the session class, and then call
Session.begin()
every time that is need, directly inside the functions of thedata/sql.py
module.(The overall idea, after changing the call, is to use the same "channels" that are currently used to propagate the
session
object, to propagate instead theSession
class)The text was updated successfully, but these errors were encountered: