4

Similar to this question wxPython + PyObjC causes app to crash at the end however there code has more superfluous code.

I have the following two samples of code, the latter crashes the former runs fine.

The only difference in the code is the order of the imports.

This code runs fine.

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

This code runs segfaults when program stops running.

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

How to replicate

  1. Make sure pyobjc is installed and you can import objc
  2. Make sure wxPython is installed (it seems both 2.9 and 3.0 are effected)
  3. run command python file
Zimm3r
  • 3,369
  • 5
  • 35
  • 53

1 Answers1

0

Temporary Solution

Note: This only works in specific cases and is still rather a hack and so shouldn't be used always.

This seems to work but is distasteful as it only fixes the error not the underlining code problem

Make sure you import objc before you import wx or any of your libraries do (for example I had to do it before I used twisted networking library too as I installed a reactor that worked with wx (and so it imported wx)).

Zimm3r
  • 3,369
  • 5
  • 35
  • 53