【问题标题】:wxPython check if the c++ part is deletedwxPython 检查 c++ 部分是否被删除
【发布时间】:2016-05-30 13:02:01
【问题描述】:

我正在处理一个项目,其中一个函数由于任务延迟而抛出 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有同样的问题,原来答案是一样的。我写不出几乎重复的,所以把这个问题概括为适用于旧的 wx。

标签: python python-2.7 wxpython wxwidgets


【解决方案1】:

事实证明,与 wx 2.8 相比,在调用 Destroy() 或类似名称之后,您首先必须使用 wx.Yield()。然后这些事件得到处理和销毁。

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

【讨论】:

    猜你喜欢
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 2014-05-11
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多