【发布时间】: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