Psycopg and threads problem

Alban Hertroys alban at magproductions.nl
Tue Sep 21 09:48:26 EDT 2004


Istvan Albert wrote:
> Istvan Albert wrote:
> 
>> have a commit at the end of your insert threads. That way
>> when all the inserts are finished the data will be available
>> for the combine thread.
> 
> I forgot this, if the commit after insert is unfeasible
> you could store the db connections in a data structure shared across 
> threads
> and if/when all the insert threads complete without errors you can call 
> commit
> on each of these before the combine thread.

That's what I already do, actually. It would be kind of difficult to use 
the same database session/transaction amongst different connections 
(that, as mentioned, could incidentally be the same due to pooling).

I pass an application context to every object in the application, and 
that includes a database connection. I spawn cursors from that single 
connection.

> Sounds a bit hackish though, just an idea.

Not really, if you want to use the transaction handling in your DBMS.

> Istvan.



More information about the Python-list mailing list