title: Share connection to postgres db across processes in Python
body: <p>I have a Python script running as a daemon. At startup, it spawns 5 processes, each of which connects to a Postgres database. Now, in order to reduce the number of DB connections (which will eventually become really large), I am trying to find a way of sharing a single connection across multiple processes. And for this purpose I am looking at the <code>multiprocessing.sharedctypes.Value</code> API. However, I am not sure how I can pass a <code>psycopg2.connection</code> object using this API across processes. Can anyone tell me how it might be done?</p>
  
  <p>I'm also open to other ideas in order to solve this issue.</p>
  
  <p>The reason why I did not consider passing the connection as part of the constructor to the 5 processes is mutual exclusion 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?</p>