title: psycopg2 : cursor already closed
body: <p>I am using <code>psycopg2 2.6.1</code>. I have a bunch of queries that I need to execute in sequence.</p>
  
  <pre><code>conn = psycopg2.connect(database=redshift_database,
                          user=redshift_user,
                          password=os.environ.get("PGPASSWORD"),
                          host=redshift_cluster,
                          port=redshift_port)
  cursor = conn.cursor()
  
  queries = [q1, q2, q3....] ## a list of queries 
  for query in queries:
      try:
          cursor.execute(query)
      except:
          print e.message
  </code></pre>
  
  <p>Suppose <code>q1</code> fails with <code>SSL connection has been closed unexpectedly</code>. Then my rest of the queries also fail with <code>cursor already closed</code>. How can I ensure that if one query fails then the following queries are executed successfully. </p>