I think the easiest solution would be to just override the thread-local context; after creating your sqlalchemy engine, run

engine.context = attrdict()

where attrdict is defined as in this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/361668

I'm about 60% confident this will work :)

On 3/28/06, Koen Bok < [EMAIL PROTECTED]> wrote:
Okay, I have a Cocoa model-view-controller application. The controller is very basic, it has a fetchall function to get all the data and to put it in a list. In the interface I can change some stuff. By pressing a button bound to the commit function I'd like to start a thread which calls an objectstore.commit to store changes in the database.

Full code:

#
#  TestAppDelegate.py
#  Test
#

from Foundation import *
from AppKit import *
from db_objects import *
import threading

from PyObjCTools import NibClassBuilder
class AppController(NibClassBuilder.AutoBaseClass):
orders = []

order_mapper = Order.mapper.options(
eagerload('person'),
eagerload('orderproducts'),
eagerload('orderproducts.product'))
def commit_(self):
# This does not work! 
# th = threading.Thread(target=objectsore.commit , name='updating database')
# th.start()
objectstore.commit()
def fetchall_(self):
orders = list(self.order_mapper.select(limit=10))
# This is needed in order to use cocoa bindings
for order in orders:
order.orderproducts_list = order.orderproducts.data
self.orders = orders



On 29-mrt-2006, at 1:51, 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()



--
Jonathan Ellis
http://spyced.blogspot.com

Reply via email to