与此问题wxPython + PyObjC causes app to crash at the end类似,但代码中包含更多多余的代码。
我有以下两个代码示例,后者崩溃前运行正常。
代码的唯一区别是导入的顺序。
import time
# note that the line is before this is so the code does work this is the only
# change that seems to matter
# need the following line to be AFTER wx import otherwise runs fine
import objc # or import Foundation or probably any objc library
import wx
# need the following line
app = wx.App(redirect=False)
# sleep shows it is ONLY when the code finally ends not before
time.sleep(3)
# you don't even need the MainLoop call
import time
import wx
# need this line to be AFTER wx import otherwise runs fine
import objc # or import Foundation or probably any objc library
# need the following line
app = wx.App(redirect=False)
# sleep shows it is ONLY when the code finally ends not before
time.sleep(3)
# you don't even need the MainLoop call
答案 0 :(得分:0)
注意:这仅适用于特定情况,并且仍然是一个黑客,所以不应该一直使用。
这似乎有效,但令人反感,因为它只修复错误而不是下划线代码问题
确保在导入wx之前导入objc 或导入任何库(例如我在安装之前必须先使用双绞网库)与wx一起工作的反应堆(因此它导入了wx))。