我在 Python 3.5 中使用 mysqlclient v1.3.10。连接到数据库后,您将获得一个连接对象,您可以从该对象获得一个用于运行查询的游标对象。
这些对象线程安全吗(即我可以创建一组然后在多个不同的 python 线程之间共享和使用它们吗)?
请您参考如下方法:
看来你不能。 MySQLdb documentation状态(向下滚动到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. You can certainly do things like cache connections in a pool, and give those connections to one thread at a time. If you let two threads use a connection simultaneously, the MySQL client library will probably upchuck and die. You have been warned.
