Psycopg and threads problem

Michael Fuhr mfuhr at fuhr.org
Mon Sep 20 10:08:32 EDT 2004


Alban Hertroys <alban at magproductions.nl> writes:

> 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.

I just wrote a small test program and was unable to duplicate your
problem -- the inserting threads ran, then the collecting thread
saw the data.

Without seeing your code we can only guess at what's wrong.  Please
post the simplest program that reproduces the problem.

What versions of Python, psycopg, and PostgreSQL are you using?
What operating system and version are you running on?

> Is there a way to tell psycopg or python to wait until the insert took 
> place?

In my test program, the inserting threads called conn.commit() and
then exited.  I then joined all of the inserting threads before
starting the collecting thread.  You could also use a condition
variable to signal when the inserts have been committed.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



More information about the Python-list mailing list