gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:38:35 24 4
gpt4 key购买 nike

我正在做一个项目,其中一个函数由于任务延迟而抛出 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com