On Mar 4, 2011, at 10:32 AM, Michael Bayer wrote:

> 
> On Mar 4, 2011, at 2:58 AM, Lenza McElrath wrote:
> 
>> Hello!  I'm iterating over a session to look at all the objects:
>> 
>> for obj in session:
>>   do_something_cool(obj)
>> 
>> Yesterday this caused what looks like a deadlock in SQLAlchemy code.  Here 
>> is the stack I grabbed using gdb:
>> /python2.5/sqlalchemy/orm/session.py:1353 (Session.__iter__)
>> /python2.5/sqlalchemy/orm/identity.py:184 (WeakInstanceDict.values)
>> /python2.5/sqlalchemy/orm/identity.py:188 (WeakInstanceDict.itervalues) ** 
>> self._remove_mutex.acquire()
>> /python2.5/sqlalchemy/orm/state.py:501 (MutableAttrInstanceState.__resurrect)
>> /python2.5/sqlalchemy/orm/attributes.py:925 (Events.run)
>> /python2.5/sqlalchemy/orm/mapper.py:2424 (_event_on_resurrect)
>> /python2.5/sqlalchemy/util.py:953 (OrderedSet.__iter__)
>> /python2.5/sqlalchemy/orm/state.py:477 (MutableAttrInstanceState._cleanup)
>> /python2.5/sqlalchemy/orm/identity.py:139A (WeakInstanceDict.remove) ** 
>> self._remove_mutex.acquire()
>> I'm running SQLAlchemy 0.6.5.  Is this a known issue or am I doing something 
>> wrong?
> 
> I've never seen that before.    A reentrant mutex would fix this but I really 
> hate to use those as they have a big performance hit and thats a very 
> critical section.   Its true this is also related to "mutable" attributes 
> which is something I'd eventually like to remove entirely - they are pending 
> deprecation in 0.7.   Is this issue consistently reproducible and can you 
> send me a test case ?   This would be very high priority.      
> 
> Not sure if this helps but one of the triggers there is you have an object 
> that has "mutable" attributes on it, which is dirty, and has been garbage 
> collected.   The "state" hangs around in the Session and when accessed 
> resurrects itself.  At that point, it seems like some other object that was 
> also garbage collected starts doing the same thing before the process for 
> object #1 can complete, its not clear why that would happen here, thats the 
> point at which I'd want to pdb around to see what that's about.


OK I can't reproduce it, but thinking about the problem I think even using an 
RLock wouldn't help anyway since then you'd get a "dictionary changed size 
while iterating" error.    So my current thoughts on this issue are at 
http://www.sqlalchemy.org/trac/ticket/2087 , which includes a patch against 0.7 
which removes the mutexing and takes a different approach to the issue of items 
disappearing while the session is being iterated.   If this issue is one you 
get often, feel free to apply it against 0.7 and try it out.    The patch needs 
tests to prove that the mechanism actually works.


-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to