QApplication实例导致python shell缓慢 [英] QApplication instance causing python shell to be sluggish

查看:189
本文介绍了QApplication实例导致python shell缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实例化QApplication对象后,我的IPython shell变得迟钝。例如,即使从一个新的开始,以下代码将使我的shell缓慢到必须重新启动它。

 来自PyQt4导入QtGui 
app = QtGui.QApplication([])

一旦是提交,我的打字变得滞后2或3秒。我的计算机并不出色,但我仍然有足够的可用内存,而且只有python shell才会受到影响。我已经尝试了默认的python解释器和ipython解释器,但结果相同。有什么建议吗?



更新:我还尝试使用%run 魔术命令,当我关闭生成的Hello World窗口后,当控件返回到ipython时,它具有相同的效果;外壳变得迟钝,我的打字开始滞后2-3秒。

解决方案

这可能有所帮助:

  QtCore.pyqtRemoveInputHook()



< blockquote>

第一次导入QtCore模块时,它会安装
Python输入钩子(即它设置Python的PyOS_InputHook
变量的值)。这允许在应用程序运行时在解释器
提示符下输入命令。然后可以
动态创建新的Qt对象并调用任何现有
Qt对象的方法。



输入挂钩可能导致问题某些类型的申请,
,特别是那些通过不同的
提供类似设施的申请。此函数删除由PyQt安装的输入挂钩。



可以使用pyqtRestoreInputHook()
函数恢复输入挂钩。


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


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.

解决方案

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

这篇关于QApplication实例导致python shell缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆