On Jan 12, 2010, at 4:26 AM, Jules Stevenson wrote: > Hi List, > > I've been trying to work out exactly how I can safely use the session > object in a threaded application. I've read the session docs, and > posts such as this one: > > http://mail.google.com/mail/#search/label%3Asqlalchemy+session+threading/1259f8c18a4d2578 > > But I am struggling a little, but I think it may have more to do with > the 'design' of the app. The app looks at a db table for 'events' to > process. A threadpool periodically takes these mapped db objects and > puts them into a list, and then threads pick up these tasks. Each > thread has it's own session object. > > This is giving me all the usual MySQL threading type issues that > others encounter. I have a hunch as to what the problem is (and is > just a hunch, so apologies if totally wrong): because the 'queued' > tasks are mapped dbobjects, they we're created in another session? > Therefore they don't play well with the thread's local session?
most likely. when a thread in your queue gets a hold of a new object, merge() it into the local session, using the returned object. or when you put objects on the queue, expunge() them from their source session first. that way you dont use state which is still associated with the originating session.
-- 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.
