H12.5: PyQt4 (thread safe) + MySQLdb (not thread safe)

   3367   3   1
User Avatar
Member
11 posts
Joined: Nov. 2006
Offline
Hi guys!

I use the python modules PyQt4 and MySQLdb in Houdini. Each for it's own works. However, if I create a tool using a combination of them both results in the MySQLdb module not working.

As I understands it, when creating a PyQt4 tool it needs to be executed in a separate thread. This is not a problem for PyQt4 since it's thread safe. However, MySQLdb is not thread safe. That's why it fails with errors. Has anyone figured out a way around this? I'm trying to force PyQt4 into the main thread so it will block Houdini, but not figured out how yet.

(as reference, Maya and Nuke do not have this problem since it's somehow runs in the main thread without blocking anything.. so MySQLdb works perfect there in PySide/PyQt4 tools)

Thanks
User Avatar
Member
1922 posts
Joined: Nov. 2006
Offline
Have you tried this method of running PyQt from inside Houdini's UI event loop? It's generally much better than the old method of using a separate thread.

http://www.sidefx.com/docs/houdini12.5/hom/cookbook/pyqt/part1/ [sidefx.com]
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
11 posts
Joined: Nov. 2006
Offline
Yeah that was my first attempt. MySQLdb didn't like it at all.

Right now I'm trying out another approach using PyQt4's SQL module but I just came to realize that the “QMYSQL” driver was not installed by default when I compiled PyQt4 so I'm going to redo that process and try to make it work. Will post my results here when I'm done!
User Avatar
Member
11 posts
Joined: Nov. 2006
Offline
By using PyQt4's provided QtSql module I was able to skip the MySQLdb module and therefor solved my issue! The only thing that wasn't clear was that the MySQL driver "QMYSQL" you need to supply for the QtSql module is not a part of the default installation.

My first thought was that I had to recompile PyQt4 but it turned out that I only had to install the qt-mysql package on my machine using the OS's package system
  • Quick Links