err, thast a little jumbled up...you dont need to use get_session since you already have the session you want to work with...get_session() also does not take a "Session" object as the argument, it takes an object instance which has an associated Session.

the basic idea, using the methods youre getting at, looks like:

session = objectstore.Session()
x = Order(_sa_session =session)
orders = list(self.order_mapper.using(session).select(limit=10))

# do stuff

# commit, can do it in any thread
session.commit()

On Mar 29, 2006, at 3:34 AM, Koen Bok wrote:

Cool, I got it working using the following code. Is this the 'Right Way©'?

class AppController(NibClassBuilder.AutoBaseClass):
orders = []
threads = []
session = None

order_mapper = Order.mapper.options(
eagerload('person'),
eagerload('orderproducts'),
eagerload('orderproducts.product'))
def commit_(self):
th = threading.Thread(
target=objectstore.get_session(self.session).commit,
name='Updating Database')
th.start()
def fetchall_(self):
self.session = objectstore.Session()
x = Order(_sa_session=self.session)
orders = list(self.order_mapper.select(limit=10))
for order in orders:
order.orderproducts_list = order.orderproducts.data
self.orders = orders


On 29-mrt-2006, at 3:12, Michael Bayer wrote:


the default behavior is that changes to objects are logged in a session
that is local to the current thread.

this can be modified in two basic ways:  using per-object sessions, or
changing the algorithm used to get the current session.

these are now documented !  here:




Jonathan Ellis wrote:
I'm pretty sure that committing in a separate thread will commit objects
modified in that thread only, since SA's unit-of-work is thread-local.

Perhaps we can suggest an alternative if you give more info on what you're
trying to accomplish.

On 3/28/06, Koen Bok <[EMAIL PROTECTED]> wrote:

Hmm I was too soon. This still does not work. No errors, the the db just
does not get updated...
This works perfect, but no threads...

def commit_(self): objectstore.commit()


On 29-mrt-2006, at 1:24, Jonathan Ellis wrote:

Since you don't say what your error is, I will just show how to make
your
code more like Python and less like Java. :)

th = threading.Thread(target=objectsore.commit, name='updating
database')
th.start()

That's it!

(And you can use threading.enumerate if you need a list of threads...)

On 3/28/06, Koen Bok <[EMAIL PROTECTED]> wrote:

Hi I would like to wrap a thread around objectstore.commit () I could
not get it to work.
What am I doing wrong?
class Controller(Object):

threads = []
 def commit_(self):
t = CommitChanges(objectstore)
self.threads.append(t)

class CommitChanges(Thread):
def __init__ (self, objectstore):
Thread.__init__(self)
self.description = "Updating Database"
self.objectstore = objectstore
self.start()

 def run(self):
self.objectstore.commit()




--
Jonathan Ellis





--
Jonathan Ellis




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
_______________________________________________
Sqlalchemy-users mailing list


Reply via email to