Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python mysqldb multiple cursors for one connection

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") 
like image 743
IT Ninja Avatar asked Aug 13 '12 01:08

IT Ninja


People also ask

Is Python MySQL connector thread safe?

The MySQLdb documentation states (scroll down a little further to threadsafety): The general upshot of this is: Don't share connections between threads. It's really not worth your effort or mine, and in the end, will probably hurt performance, since the MySQL server runs a separate thread for each connection.


1 Answers

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.

like image 144
bbenne10 Avatar answered Sep 21 '22 15:09

bbenne10