Le vendredi 1 avril 2016 02:30:21 UTC+2, Mike Bayer a écrit : > > > > On 03/31/2016 10:38 AM, Mehdi GMIRA wrote: > > > > > > > > 1) One limitation that i find to the scoped_session is that > you're > > > limited to exactly one session by thread. > > > > that's not true at all, make as many sessions as you want from the > > sessionmaker() inside of it (or just use Session()) > > > > > > Yes but then you'd have to import explicitly the engine and > > sessionmaker(), which seems a little bit awkward. What i meant is that > > once you start using scoped_session instead of Session(), it becomes > > awkward to create multiple sessions within the same thread. > > the session_factory provides this: > > session = my_scoped_session.session_factory() > > Ok, I wasn't aware of this function. Thanks !
> > > > > > > i dont see any intrinsic issue with spawning threads inside a > context > > manager any more than if you did so inside of an "if:" statement > > > > > > Isn't there a risk that you'd be passing objects that are > > session-dependant to other threads ? > > Using a context manager for a block of code doesn't have any impact on > what the code is doing with objects inside that block so I don't see how > those two things are related. > > > I think I'm not being clear. What i mean is that If you only use a session as a context manager, you don't have to think about Session() not being thread safe, unless you're inside that context manager. But since scoped_session has session_factory(), I think that as you said, scoped_session is indeed the way to go if the application is multithreaded. Thank you for your patience :) > > > > > -- > > 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+...@googlegroups.com <javascript:> > > <mailto:sqlalchemy+unsubscr...@googlegroups.com <javascript:>>. > > To post to this group, send email to sqlal...@googlegroups.com > <javascript:> > > <mailto:sqlal...@googlegroups.com <javascript:>>. > > Visit this group at https://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. > -- 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 https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.