Connecting to postgres db through processes in Python

I have a Python script working as a daemon. When launched, it starts 5 processes, each of which connects to the Postgres database. Now, to reduce the number of database connections (which will eventually become really large), I am trying to find a way to share a single connection for several processes. And for this, I look at the API multiprocessing.sharedctypes.Value. However, I'm not sure how to pass an object psycopg2.connectionusing this API through processes. Can someone tell me how to do this?

I am also open to other ideas to solve this problem.

The reason why I did not consider transferring the connection as part of the constructor in 5 processes is the mutual exception handling. I am not sure how I can prevent more than one process from accessing the connection if I follow this approach. Can someone tell me if this is the right thing to do?

+1
source share
1 answer

. , , . , , .

, , , . . .

Python, fifos .. .

+6

All Articles