Python 3.4 : PyQt on Windows: Crash on exit only on some computers

标签 python crash pyqt exit crash-dumps

我有一个 Python 程序,用 cx_freeze 打包以使其可执行。该程序严格来说是一个用于数据采集的桌面程序。它在每台计算机上工作正常并且退出正常,但在我们的一位合作者的一台装有 Windows 7 的桌面上,它仅在退出时崩溃(我强调没有给出 pythonic 错误。只是一个低级崩溃,有关零信息它)。只需启动和退出程序就会使其崩溃!

我让那个人为我创建了一个内存转储,他做到了。奇怪的部分如下:从中创建内存转储并使用 WinDbg 对其进行分析会产生以下错误链:

STACK_TEXT:  
WARNING: Stack unwind information not available. Following frames may be wrong.
0020f940 5c51b34e 5c7bd640 9d7a3385 03c93748 QtCore4!QHashData::free_helper+0x26
0020f974 76e314bd 00b30000 00000000 03e0c4c0 QtGui4!QGestureRecognizer::reset+0x1f9e
0020f9a0 5c51c968 03c93748 5d3608c2 00000001 kernel32!HeapFree+0x14
0020f9a8 5d3608c2 00000001 03c93748 03891250 QtGui4!QGestureRecognizer::reset+0x35b8
0020f9c0 5d3627b5 9d0dae1c 03891250 03cac0a0 QtCore4!QObjectPrivate::deleteChildren+0x72
00000000 00000000 00000000 00000000 00000000 QtCore4!QObject::~QObject+0x3e5

现在令我惊讶的是来自 QGestureRecognizer (即 part of QtGUI apparently )的投诉!但为什么?我不使用任何触摸功能!我使用的模块是:QtCoreQtGUI。这是从哪里来的?我可以强制禁用与该类相关的所有内容吗:QGestureRecognizer?在这种情况下你会怎么做?

更新:

此问题似乎仅发生在 Windows 7 计算机上。在两台Windows 7电脑上进行测试,都出现了同样的崩溃情况。

最佳答案

释放内存似乎遇到问题。您可以尝试使用类似这样的函数手动执行此操作:

def clean(item):
    """Clean up the memory by closing and deleting the item if possible."""
    if isinstance(item, list) or isinstance(item, dict):
        for _ in range(len(item)):
            clean(list(item).pop())
    else:
        try:
            item.close()
        except (RuntimeError, AttributeError): # deleted or no close method
            try:
                item.deleteLater()
            except (RuntimeError, AttributeError): # deleted or no deleteLater method
                pass

然后在主小部件中定义清洁方法。

class MyWindow(QWidget):
    def cleanUp(self):
        # Clean up everything
        for i in self.__dict__:
            item = self.__dict__[i]
            clean(item)

最后,在调用 qt_app._exec() 之前,您必须像这样进行连接:

qt_app.aboutToQuit.connect(app.cleanUp)

其中 app 是您的主窗口。

<小时/>

编辑:

if __name__ == '__main__' 行下的所有内容包装到单个 main() 函数中有时会起作用,但我不知道为什么。

关于Python 3.4 : PyQt on Windows: Crash on exit only on some computers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38590263/

相关文章:

python - 如何在 OpenCV Python 中为深度图更改 cv2.StereoBM_create 的属性

python - 为什么设置 ctypes dll.function.restype=c_void_p 返回 long?

python - 带边框半径的 QMovie

python - PyQt 将 QWidget 的方向从右向左更改

python - 如何使用通过 webdriver_manager 安装的 ChromeDriver 更改 Google Chrome UserAgent

python - 使用 python 查找视频中的图像

objective-c - 在哪里寻找错误。文档、应用程序委托(delegate)或两者兼而有之?

jquery - 具有指定jsonpCallback的jQuery 1.4.2 $ .ajax使IE6/7崩溃

c++ - qt 应用程序崩溃但不容易重现,我已经捕获了转储堆栈以及如何通过堆栈查找源代码

python - QT 中的 webView.load(QUrl) 和 QNetworkAccessManager.get(Qurl) 有什么区别?