[PyKDE] deadlock with QThread
Phil Thompson
phil at river-bank.demon.co.uk
Tue Aug 27 14:45:01 BST 2002
Greg Fortune wrote:
> Phil,
>
> We've managed to create a very nasty deadlock using the QThread class in an
> application we are developing. I've attached some sample python code that
> demonstrates several cases in which QThread does work and one case in which
> it does not.
>
> Our application's code is closest to test case 4, but our code still does not
> work. Regardless, test case 2 needs addressed and probably fixed :) It is
> also possible that we just aren't using the QThread stuff correctly and in
> that case, I'd love to know what we've missed.
>
> btw, the deadlock occurs when trying to import any module inside the
> QThread.run call. Any function level imports in any code called by
> QThread.run lock up the thread and any imports directly in the QThread.run
> call lock up the thread.
>
> Oddly enough, imp.load_module() allows us to get around the bug, but only for
> standard python modules (perhaps because they are loaded as an .so??). 3rd
> party modules fail even in an imp.load_module() even though imp.find_module
> is successful. Also, removing any function level imports also fixes the
> problems, but the imports that cause problems are not in our code. They are
> actually in the MySQLdb module, but any module doing a function level import
> will cause the lock...
>
> I'm still trying to determine what makes our code different from test case 4,
> which runs. If I figure that out, I'll send another test case that does not
> work... Until then, let me know what you find out with regards to test case
> 2.
>
> To execute test case 2, just run
> ./threadtest.py 2
I haven't had a chance to look at this in detail, but here are some
thoughts...
In case 2 you are nesting imports, in case 3 you aren't. Python
maintains an lock that prevents a module being imported by different
threads at the same time. My guess is that the import lock is
deadlocked. This then implies that the problem is a feature and
unrelated to Qt's thread classes. My guess then would be that you would
see the same problem if you used the standard Python thread module and
didn't use PyQt at all.
Phil
More information about the PyQt
mailing list