error when use multithreading and mysqldb

前端 未结 3 575
滥情空心
滥情空心 2020-12-29 00:54

getting error when multithreader program access data .

Exception in thread Thread-2:

ProgrammingError: (2014, \"Commands out of sync; you can\'t run this co         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 01:06

    here is detail about the error: http://dev.mysql.com/doc/refman/5.0/en/commands-out-of-sync.html.

    Mysqldb's manual suggest these:

    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.

    For threaded applications, try using a connection pool. This can be done using the Pool module

    See more information search keyword threadsafety on MySQLdb manual,

提交回复
热议问题