[PyQt] PyOS_InputHook

Phil Thompson phil at riverbankcomputing.co.uk
Wed Sep 5 17:55:41 BST 2007

On Wednesday 05 September 2007, Martin Teichmann wrote:
> Hi,
> 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

It's fixed in current snapshots, both that particular error message and the 
addition of QtCore.pyqtRemoveInputHook().


More information about the PyQt mailing list