python mysqldb一个连接的多个游标 [英] python mysqldb multiple cursors for one connection

查看:122
本文介绍了python mysqldb一个连接的多个游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您有一个连接对象时,是否可以对一个连接建立多个游标,并同时使用这些游标执行查询?还是每个游标都等待上一个游标完成查询?

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")

推荐答案

您需要打开多个连接. Mysqldb是线程安全的,因此每个连接将能够访问它们各自的游标,查询和结果集,而不会影响其他连接,但是每个线程或进程将需要自己的连接.

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.

这篇关于python mysqldb一个连接的多个游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆