[sqlalchemy] how to handle deadlock

1,857 views
Skip to first unread message

rajasekhar911

unread,
May 6, 2010, 6:23:06 AM5/6/10
to sqlalchemy
Hi

I am using sqlalchemy0.5.5 in my TG2 app with mysql(innodb) database
My applicaton is multithreaded.
there are multiple tasks that run at certain intervals.
in one of my tables i am getting the following deadlock error.
Deadlock found when trying to get lock; try restarting transaction

the query was failing while trying to delete in the following way.
DBSession.query(Metrics).filter(Metrics.type_id==type_id).filter(Metrics.cdate
<= date1).delete()

so i changed the code to
rows =
DBSession.query(Metrics).filter(Metrics.type_id==type_id).filter(Metrics.cdate
<= date1).all()
for row in rows :
DBSession.delete(row)
assuming that it will scan less no:of rows while deleting. In this way
i am no longer seeing the deadlock error.
but if anybody can clarify that this is reliable enough or suggest any
other options ,
that would be really helpful

thanks

--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

gary clark

unread,
May 6, 2010, 7:56:57 AM5/6/10
to sqlal...@googlegroups.com
try:

Perform table transaction
break
except:
rollback
delay
try again to perform table transaction

I'm sure you will get the gist of the above and why. I also set my isolation_level to READ UNCOMMITED.

Thanks,
Garyc


--- On Thu, 5/6/10, rajasekhar911 <rajase...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages