Psycopg and threads problem

Adrien Di Mascio adim at nospam.com
Tue Sep 21 02:46:47 EDT 2004


Hi,

>> I'm using psycopg to insert records in a number of threads. After the
>> threads finish, another thread runs to collect the inserted data. Now,
>> my problem is that psycopg let's my threads end before the inserts
>> actually took place, resulting in my collecting thread finding no
>> records... They are inserted after it checks.
>> 
>> Is there a way to tell psycopg or python to wait until the insert took
>> place?
> 
> I believe turning autocommit on in the connection would achieve this (at
> the expense of performance and transaction support).  You could also add
> a "commit" SQL statement to each thread.

I'm just doing a quick reply here, since I've only skimmed through all
posts in this thread, but I think, as you said, that turning autocommit on
will solve the problem. Also notice that the autocommit() will be
deprecated (if not yet), so you should consider using the
"set_isolation_level()" method.

Doing something like this should do the trick :

cnx = psycopg.conenct('dbname=your_db user=your_user')
cnx.set_isolation_level(1)

This way, you should be able to access written data from other threads or
processes

You may find more information here :

http://lists.initd.org/pipermail/psycopg/2004-February/002577.html

Hope this helps,
Cheers,
Adrien.

--
LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr   http://www.logilab.org




More information about the Python-list mailing list