Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QApplication instance causing python shell to be sluggish

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.

like image 906
bdiamante Avatar asked Oct 05 '22 06:10

bdiamante


1 Answers

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

like image 194
warvariuc Avatar answered Oct 07 '22 19:10

warvariuc