程序退出结束时pyobjc和wx崩溃

时间:2014-04-04 16:54:55

标签: python objective-c segmentation-fault wxpython pyobjc

与此问题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

如何复制

  1. 确保已安装pyobjc,您可以导入objc
  2. 确保安装了wxPython(似乎2.9和3.0都有效)
  3. 运行命令python 文件

1 个答案:

答案 0 :(得分:0)

临时解决方案

注意:这仅适用于特定情况,并且仍然是一个黑客,所以不应该一直使用。

这似乎有效,但令人反感,因为它只修复错误而不是下划线代码问题

确保在导入wx之前导入objc 导入任何库(例如我在安装之前必须先使用双绞网库)与wx一起工作的反应堆(因此它导入了wx))。