【发布时间】:2014-05-17 02:43:40
【问题描述】:
类似于这个问题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
如何复制
- 确保 pyobjc 已安装并且可以导入 objc
- 确保已安装 wxPython(似乎 2.9 和 3.0 都受影响)
- 运行命令python 文件
【问题讨论】:
-
我花了一段时间才看到这两个文件的区别......但这是一个很好的问题,恕我直言
-
是的,它实际上只是切换了两行,它会导致一个段错误,如果不烦人的话,这是相当惊人的。
标签: python objective-c segmentation-fault wxpython pyobjc