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

标签 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 文件

最佳答案

临时解决方案

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

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

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

关于python - 程序退出结束时 pyobjc 和 wx 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22868669/

相关文章:

带有 calloc 的 C 段错误

c++ - 在迭代期间调用集合上的 erase()

python - 如何在pygame中让一个矩形依次出现?

python - IPython 手动迭代主循环?

python - 如何使用python控制 screen 进程

ios - iOS 7上的动画问题,但iOS 8上没有

ios - 隐式转换丢失整数精度 : 'unsigned long' to 'int' (causes app to crash)

objective-c - 检测isIpad的更好方法?

c - 使用 C 的 MPI 分段故障 MPI_Scatter

python - 为什么我的测试 sqlite 数据库的 'filling' 占用了这么多 RAM 并且没有保存任何内容?