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 [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
-~----------~----~----~----~------~----~------~--~---