title: multiprocessing how to close db connections for each thread
body: <p>I am creating a db connection for each thread and was wondering what the best way to close these connections when I am done. </p>
  
  <p>Here is my code where I initialized my db connection and call pool</p>
  
  <pre><code>class Processor(object):
      def __init__(self, DSN):
          self.dsn0= DSN[0]
          self.dsn1= DSN[1]
          self.conn0 = None
          self.conn1 = None
  
  
      def __call__(self, data):
          if(self.conn0 is None and self.conn1 is None):
             self.conn0 = psycopg2.connect(self.dsn0)
             self.conn0Curs = self.conn0.cursor()
             self.conn1 = psycopg2.connect(self.dsn1)
             self.conn1Curs = self.conn1.cursor()
         sql = generateQuery(*data)
         print(sql)
  
  
  
  if __name__ == '__main__':
  
      pool = ThreadPool()
      pool.map(Processor([DSN1, DSN2]), batches)
      pool.close()
      pool.join()
  </code></pre>