【问题标题】:pyobjc and wx crash when program exits ends程序退出结束时pyobjc和wx崩溃
【发布时间】: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

如何复制

  1. 确保 pyobjc 已安装并且可以导入 objc
  2. 确保已安装 wxPython(似乎 2.9 和 3.0 都受影响)
  3. 运行命令python 文件

【问题讨论】:

  • 我花了一段时间才看到这两个文件的区别......但这是一个很好的问题,恕我直言
  • 是的,它实际上只是切换了两行,它会导致一个段错误,如果不烦人的话,这是相当惊人的。

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


【解决方案1】:

临时解决方案

注意:这仅在特定情况下有效,并且仍然是一种 hack,因此不应始终使用。

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

确保在导入 wx 之前导入 objc你的任何库(例如,我必须在安装时使用扭曲网络库之前这样做一个与 wx 一起工作的反应器(因此它导入了 wx))。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多