MySQLdb - libmysqlclient_r stuck on read()

464 Views Asked by At

I am writing a multi-threaded python application that read/write to a MySQL DB (using MySQLDB and libmysqlclient_r - thread safe library).

At some point (not sure why or when), one of the threads stuck.

#0  0x00007f6c124ad14d in read () from /lib/libpthread.so.0
#1  0x00007f6c0d78f759 in vio_read_buff () from /usr/lib/libmysqlclient_r.so.16
#2  0x00007f6c0d79086f in ?? () from /usr/lib/libmysqlclient_r.so.16
#3  0x00007f6c0d790c75 in my_net_read () from /usr/lib/libmysqlclient_r.so.16
#4  0x00007f6c0d78afca in cli_safe_read () from /usr/lib/libmysqlclient_r.so.16
#5  0x00007f6c0d78b7a9 in ?? () from /usr/lib/libmysqlclient_r.so.16
#6  0x00007f6c0d789adc in mysql_real_query () from /usr/lib/libmysqlclient_r.so.16
#7  0x00007f6c0db24aad in ?? () from /usr/lib/pymodules/python2.6/_mysql.so
#8  0x00000000004a7ba5 in PyEval_EvalFrameEx ()
#9  0x00000000004a84a0 in PyEval_EvalFrameEx ()

Any idea why read () does not return? It happens once in a while.

Note! There are about 6 different threads that connect to this DB and query/execute on it on.

Could it be a bad Query string? Bad usage of API?

1

There are 1 best solutions below

0
On

If you are sharing a single connection between threads, that's the problem. The MySQL client library/protocol does not allow for that. You can safely give each thread it's own connection, and they will not block each other.