Psycopg; How to detect row locking?
Cliff Wells
clifford.wells at comcast.net
Wed Sep 29 09:30:20 EDT 2004
On Mon, 2004-09-27 at 13:40 +0200, Alban Hertroys wrote:
> Good day,
>
> I have a number of threads doing inserts in a table, after which I want
> to do a select. This means that it will occur that the row that I want
> to select is locked (by the DB). In these cases, I believe I receive an
> OperationalError (or is it an InterfaceError?).
>
> Is it possible (and if so - how?) to verify that the exception occured
> because of row locking, so that I can wait and try again?
I've seen this exception and frankly, it has always occurred due to row
locking. Simply retry the query until it completes.
> Or are there better ways to achieve this? I'm not too charmed about
> polling loops that may never end.
I've written multithreaded apps with hundreds of threads that used the
retry technique and never had a problem. In fact, I believe Zope uses
this method.
> I'm using python 2.3 with psycopg 1.1.13 and PostgreSQL 7.4.2.
>
> Regards, Alban Hertroys.
--
Cliff Wells <clifford.wells at comcast.net>
More information about the Python-list
mailing list