python - QApplication实例导致python shell运行缓慢

标签 python pyqt pyqt4 ipython

在我实例化一个 QApplication 对象后,我的 IPython shell 变慢了。例如,即使是从新开始,以下代码也会使我的 shell 变得非常缓慢,以至于我必须重新启动它。

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

一旦提交,我的输入就会延迟 2 或 3 秒。我的电脑不是很好,但我仍然有足够的可用内存,而且似乎只有 python shell 受到了影响。我已经尝试了默认的 python 解释器和 ipython 解释器,结果相同。有什么建议吗?

更新:我还尝试使用 %run 魔术命令在 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 - QApplication实例导致python shell运行缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14504630/

相关文章:

python - django 缓存 session 的登录问题

python - 基于 PyQt 的 GUI 中的计时器

PyQt:QGraphicsItem 添加在错误的位置

python - time.sleep() 需要保持 QThread 响应吗?

python - 更改matplotlib中zoom-rect的边缘颜色

python - Google Appengine NDB 祖先与键查询

python - 将 pytest 覆盖率和 codecov.io 与 Python 结合使用

python - 如何为实例更改 dict() 的行为

python - C 程序可以有 Python GUI 吗?

python - 如何使用pyqt4刷新小部件中的内容?