Re: psycopg2 multiprocessing problem

Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On 07/02/2010 19:43, kevin wrote:
> i am getting this error message in pg_log log directory
> 
> http://pastie.org/813651
> 
> i do not think there are any error in the queries [select, insert/updates] i
> am doing, because if i switch to threading instead of multiprocessing i dont
> get any error at all. but i want to use multiprocessing.

It seems you're using the same connection from two processes at the same
time. Threads use the same address space, so they can share the
connection because locks and shared state works. I suppose the fork()
done by multiprocess duplicates file descriptors so that the pq
connection continue to work but now you have two python connections that
don't share the same state anymore and this is bad (no locking and so
on). Just create a new connection in every process.

psycopg law number 0: never share a connection between processes.

federico

-- 
Federico Di Gregorio                                       fog-NGVKUo/i/[email protected]
                           There's no certainty - only opportunity. -- V

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc (application/pgp-signature, 262 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktv6y8ACgkQvcCgrgZGjesDHACfVlEOsB7vawt4R5eAz27LiuKA
yD8Ani1VBTusjn6kTUAEtkop79c22wqb
=ZIYm
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.