QApplication实例导致python shell缓慢

前端之家收集整理的这篇文章主要介绍了QApplication实例导致python shell缓慢前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我实例化QApplication对象后,我的I Python shell变得迟缓.例如,即使从一个新的开始,以下代码将使我的shell缓慢到必须重新启动它.
from PyQt4 import QtGui
app = QtGui.QApplication([])

一旦提交,我的输入就会滞后2或3秒.我的计算机并不太棒,但我仍然有足够的可用内存,而且它只是受到影响的python shell.我已经尝试了默认的python解释器和ipython解释器,但结果相同.有什么建议?

更新:我还尝试使用%run magic命令在ipython中运行一个独立的pyqt“Hello World”程序,当我关闭生成的“Hello World”窗口后,当控件返回到ipython时,它具有相同的效果;外壳变得迟钝,我的打字开始滞后2-3秒.

解决方法

这可能有所帮助:
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

猜你在找的Python相关文章