[Pythonmac-SIG] Weird Carbon: gestalt: wxPython issue/bug
Chris.Barker at noaa.gov
Thu Feb 4 18:42:49 CET 2010
Peter Hanson, on the wxPython list, seems to have identified a bug in
the gestalt module, that may be a Carbon issue. It's a bit of an unusual
case: it freezes up wxPython, when wx is called from other than the main
thread. Robin Dunn suspects that it's a Carbon issue -- gestalt is
calling Carbon, and doing so in the main thread, so you are then trying
to call Carbon from more than one thread, which may be the cause of the
problem. I've confirmed that if you call gestalt from the same thread as
wxPython, there is no failure.
A link to Robin Dunn's assessment:
As Carbon is deprecated anyway, I guess it's time for gestalt ( or
platform.mac_ver ) to be re-written
I've tested on OS-X 10.4.11, Python 2.5 and Python2.6
Here is Peter's summary and sample code:
# Demonstration of application freeze on OSX.
# Running "python osx_freeze.py" shows the symptom:
# non-responsiveness after about 3 seconds. In theory
# this will occur in any wxPython app which runs
# the GUI event loop in a thread other than the one
# in which the failing gestalt('sysu') call (see below)
# is first executed.
# Enabling any of these imports can trigger the problem
# as each one imports the next one down in the list.
# This will happen only with pkg_resources v0.6c10 or later
# although it's not pkg_resources' fault.
# import matplotlib.figure
# import matplotlib.axes
# import matplotlib.dates
# import pytz
# import pkg_resources
# The next import alone doesn't lead to failure,
# but the function call does.
# This same code is executed by pkg_resources starting
# with setuptools v0.6c10.
# from platform import mac_ver; mac_ver()
# The platform.mac_ver() call does the following, which
# is what ultimately leads to the failure. Calls
# to gestalt() with 'sysa' (for example) do not
# trigger the problem, either because the problem is
# related to the 'sysu' itself, or to the fact that
# an exception is raised because the selector "sysu"
# is no longer recognized.
from gestalt import gestalt
except Exception, ex:
print 'gestalt call failed'
if __name__ == '__main__':
app = wx.App(False)
frame = wx.Frame(None)
wx.StaticText(frame, label='Goodbye, cruel world')
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the Pythonmac-SIG