python mysqldb multiple cursors for one connection

IT Ninja picture IT Ninja · Aug 13, 2012 · Viewed 17.6k times · Source

When you have one connection object, can you make multiple cursors to that one single connection and execute queries with these cursors at the same time? Or would each cursor wait for the previous cursor to finish its query?

connection type: database=MySQLdb.connect(...)
cursor:          curs=database.cursor()
querying:        curs.execute("query")

Answer

bbenne10 picture bbenne10 · Aug 13, 2012

You'll need to open multiple connections. Mysqldb is threadsafe, so each connection will be able to access their respective cursors, queries and result sets without having an effect on the other connections but each thread or process will need its own connection.