[Twisted-Python] PyPgSQL not locking in adbapi

Jp Calderone exarkun at divmod.com
Wed Jun 1 17:05:22 EDT 2005


On Wed, 1 Jun 2005 16:27:54 -0300, Carolina Ardohain <carolinaardohain at gmail.com> wrote:
>I'm using Twisted 2.0, and pgSQL 2.4.
>
>I have two function in plpgsql that access the same table, I have to
>look if one id is in the table persons, if not then add to the table.
>I try to lock a table with "LOCK TABLE persons IN ACCESS EXCLUSIVE
>MODE;", so no both functions try to add the same id.
>
>I get 'duplicate key violates unique constraint' when run the two
>queries at the same time, if I delay one of the functions 1 sec then
>everything is fine.
>

What method did you use to run the LOCK statement?  Did you make sure it ran in the same transaction as the subsequent SELECT and UPDATE?

If you aren't already, I think you want to use one runInteraction() call for all three parts.

Jp




More information about the Twisted-Python mailing list