python - wxPython检查c++部分是否被删除

标签 python python-2.7 wxpython wxwidgets

我正在做一个项目,其中一个函数由于任务延迟而抛出 wx.pyDeadObject Error

我在 wx you can check if the c++ object still exsists by running if self: 中读到过,但是这在 wxPython 3.0.2 中不再有效。使用 wx 3。

我已将函数修改为以下内容:

def SetData(self, delayedResult):
    if not self or not self.list:
        return
    data = []
    torrents = delayedResult.get()

    for torrent in torrents:
        data.append((torrent.infohash, [torrent.name], torrent, ThumbnailListItemNoTorrent))

    self_exist = True
    list_exists = True

    if not self:
        self_exist = False
    if not self.list:
        list_exists = False

    try:
        self.list.SetData(data)
        self.list.SetupScrolling()
    except wx.PyDeadObjectError:
        print "Self existed: %s and self.list existed: %s" % (self_exist, list_exists)

它已经通过了第一个 if 语句,但是由于 delayedResutlt.get() 正在阻塞我添加了额外的 try except(我也尝试在函数的开头复制那个 if 语句,但是那没有用)。

在运行其中一个单元测试时,我得到了 Self existed: True and self.list existed: True 这证实了我的怀疑。 documentation of 3.0.3说这应该存在。

如何测试 wx 对象的 c++ 部分是否已在 wxPython 中删除?

最佳答案

事实证明,与 wx 2.8 相比,在调用 Destroy() 或类似的东西之后,您首先必须执行 wx.Yield()。然后事件得到处理和销毁。

在所有情况下,使用 bool(object) 将评估为 TrueFalse,具体取决于对象是否仍处于事件状态.

关于python - wxPython检查c++部分是否被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35480179/

相关文章:

python - wxPython:在标签按下时切换文本控制焦点

python - IOLoop.add_handler 不接受某些文件描述符

python - 保存 matplotlib 动画会导致错误

python - 如何在 Keras 2.0 中使用 InceptionV3 瓶颈作为输入

python - subprocess.call() 与 GUI (Tkinter) 交互

python - wxPython AboutDialog 图标不居中

python - 迭代列表的列表,不返回子列表中的所有项目

python-2.7 - 在 groupby 数据框中应用唯一两次

python - 子进程不引发 CalledProcessError

python - 如何用按钮调用另一个类并在类之间传递变量?