5

My IPython shell becomes sluggish after I instantiate a QApplication object. For example, even from a fresh start, the following code will make my shell sluggish enough where I have to restart it.

from PyQt4 import QtGui
app = QtGui.QApplication([])

As soon as that is submitted, my typing becomes lagged by 2 or 3 seconds. My computer is not fantastic, but I still have plenty of available memory, and it's only the python shell that seems to be affected. I've tried both the default python interpreter and the ipython interpreter with the same results. Any suggestions?

Update: I also tried running a standalone pyqt "Hello World" program in ipython using the %run magic command and when control was returned to ipython after I closed the resulting "Hello World" window, it had the same effect; the shell became sluggish and my typing starting lagging by 2-3 seconds.

bdiamante
  • 15,980
  • 6
  • 40
  • 46
  • 1
    I can't reproduce the issue. Did you try with "ipython --gui='qt'"? – Bernhard Kausler Jan 24 '13 at 16:40
  • That did it. I'm not 100% sure why this corrected the issue, but I will read the ipython docs to see exactly what this does. Since I'm also using pylab, another command that works is `ipython --pylab qt`. Thanks! – bdiamante Jan 24 '13 at 16:50

1 Answers1

4

This may help:

QtCore.pyqtRemoveInputHook()

When the QtCore module is imported for the first time it installs a Python input hook (ie. it sets the value of Python's PyOS_InputHook variable). This allows commands to be entered at the interpreter prompt while the application is running. It is then possible to dynamically create new Qt objects and call the methods of any existing Qt object.

The input hook can cause problems for certain types of application, particularly those that provide a similar facility through different means. This function removes the input hook installed by PyQt.

The input hook can be restored using the pyqtRestoreInputHook() function.

http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qtcore.html#pyqtRemoveInputHook

warvariuc
  • 57,116
  • 41
  • 173
  • 227
  • Worked like charm. As soon as the input hook was closed, the shell became responsive again and as soon as the hook was restored, it became sluggish. This was definitely the culprit it seems. Thanks! – bdiamante Jan 25 '13 at 18:59