[PyQt] PyOS_InputHook

Martin Teichmann martin.teichmann at lkb.ens.fr
Wed Sep 5 17:24:37 BST 2007


I just updated PyQt4 to the newest binary version I could find
(PyQt-Py2.5-gpl-4.3.0-b1.exe) and was first positively surprised
about all the stuff in there bundled, (great idea, btw)
but also immediately ran into a big trap: my program started to output
"QApplication::exec: Must be called from the main thread". It took me
a while to find out where it came from: the PyOS_InputHook. I was
calling raw_input from within another thread than the main thread, and,
well, this called exec which didn't like to be called.
Unfortunately I could not find any method to switch that off
(qInstallMsgHandler at least helped me in avoiding to look at
the error messages, but only with 99% CPU, a wait
in the Handler helped, though, but this is not the issue)

Now, one could ask, why am I doing such a stupid thing as calling
raw_input from within a different thread? Well, I just had tried to solve
exactly theproblem PyOS_InputHook was made for: to be able to
type commands on the commandline while the GUI is running at the
same time. I just did that using a different thread, which, in my
humble opinion, is a slightly better idea than the hook. I am not
alone: ipython (and pylab) do the very same, on their mailing list
someone already posted the problem.

So, would it be possible to disable this whole Hook thing, maybe
using some switch? Or maybe one could check to see if we are in
the main thread?

Thanks for the great work on PyQt4!


Martin Teichmann

More information about the PyQt mailing list