>Do you really want to flush session in other threads not knowing in which state they are? Uhm, that's a good point...
I just want to flush created objects wich created in my function,but belongs to other session because references to objects in other session. For example: def my_function(foo_object): for _ in xrage(10): bar = Bar(foo=foo_object) seomething_to_write_all_bar_objects_to_db() foo_object = Foo() Thread(target=my_function).start() -- Alexey Y Uzhva Everything will be all right in the end. If it's not all right, it's not the end. 2009/10/7 Tomasz Jezierski - Tefnet <develop...@tefnet.pl> > > Dnia 2009-10-07, Śr o godzinie 04:30 -0700, Alexey pisze: > > Hello. > > > > I'm using SQL Alchemy as a persistence engine for my multi-threaded > > desktop application with sqlite backend. > > > > ScopedSession acts very well, but there is a problem: > > > > 1) I have 2 tables: > > > > categories_table = Table('category', metadata, > > Column('id', Integer, primary_key=True), > > Column('name', Unicode(50)), > > ) > > > > keywords_table = Table('keyword', metadata, > > Column('id', Integer, primary_key=True), > > Column('category_id', Integer, ForeignKey('category.id')), > > Column('text', Unicode(200)), > > ) > > > > mapper(Category, categories_table,properties={ > > 'keywords': relation(Keyword, > > backref='category',order_by=keywords_table.c.text,cascade="all, delete- > > orphan") > > }) > > > > > > mapper(Keyword, keywords_table) > > > > 2) Thread A creates Keyword instance with something like this: > > new_keyword = Keyword(u'Test',category=category) > > > > Newly created `new_keyword` automagically become attached to > > `category` session manager. > > > > But not being automagically commited! > > > > `category` may be created in other thread, so calling session.flush > > () does nothing because new object doesn't belong to current session. > > > > 3) It will remain uncommited when i'm closing my application. And if > > finally get lost after application exit. > > > > > > So the question is: > > > > How to flush *ALL* sessions, regardless their threads? > > > Do you really want to flush session in other threads not knowing in > which state they are? > > Maybe try/finally will be enough for you? Something like > > --program/thread begin-- > try: > createsession > somestuff > finally: > session.flush() > --program/thread end-- > > > --- > Tomasz Jezierski > Tefnet > www.tefnet.pl > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---