我正在处理一个项目,其中由于延迟任务,一个函数会抛出 wx.pyDeadObject Error
。
我读到在 wx 中 可以通过运行 if self:
来检查 c++ 对象是否仍然存在, 但是在使用 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
,这证实了我的怀疑。 3.0.3的文档说应该存在这个东西。
如何测试wxPython中的c++部分是否已被删除?