On Aug 25, 2008, at 1:56 PM, Harish K Vishwanath wrote:

> Hello,
>
> Thank you very much for your reply!
>
> Each thread gets its own session. The first thread, after adding a  
> User object, appends its primary key into a global List. The other  
> thread which is trying to modify the object :
> - Pops an id from the global list
> - Queries the object from the DB using its own session  using the id  
> popped.
>
> This query adds the object to the second threads session, right?
>
> >>>
> Sharing the object across threads works against the transaction  
> model which you are trying to take advantage of.   Your second  
> thread is in its own transaction, and should be loading all of its  
> information from that transaction.  By hitting user.UserID in the  
> second thread, you're attempting to access database data from the  
> original transaction which "user" is still associated with and  
> concurrency related issues are occuring.
> >>>
>
> The first thread is trying to put the UserID into the gloabl list  
> (this way, it passes the id of object it just added to the second  
> thread).
>
> So, in the line where it is trying to USERIDLIST.append(user.userid)  
> in the first thread. When expire_on_commit is set to True, this  
> statement issues an internal query, and I get this exception.
>
> PS : I add around 100 users in the thread, and the below exception  
> occurs randomly during the addition.
>
> Any inputs?

its defnitely concurrent access to the Session's resources causing the  
exception (the word "randomly" is key here).    The particular error  
you're getting is something that never happens unless you hit a  
Connection object in an invalid state, like while its being closed but  
has not yet been dereferenced.    Try removing things from your app  
until you can distill the behavior into its most rudimentary features,  
which will illustrate exactly where its happening, or in the case that  
its something on SA's side which could be clarified it would serve as  
a description of the issue.


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to