OS X problem with pkg_resources and the twisted event loop
Hi, I've come across a problem with an easy_install managed package (matplotlib) on my OS X box. When I try to import it for the first time inside of a twisted application I get this nasty traceback: Traceback (most recent call last): File "/Users/mtt/Desktop/twisted_macosx_vers.py", line 12, in ? reactor.run() File "/usr/local/lib/python2.4/site-packages/twisted/internet/posixbase.py", line 206, in run self.mainLoop() File "/usr/local/lib/python2.4/site-packages/twisted/internet/posixbase.py", line 214, in mainLoop self.runUntilCurrent() --- <exception caught here> --- File "/usr/local/lib/python2.4/site-packages/twisted/internet/base.py", line 541, in runUntilCurrent call.func(*call.args, **call.kw) File "/Users/mtt/Desktop/twisted_macosx_vers.py", line 4, in get_platform import pkg_resources File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/setuptools-0.6a9-py2.4.egg/pkg_resources.py", line 534, in ? class Environment(object): File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/setuptools-0.6a9-py2.4.egg/pkg_resources.py", line 537, in Environment def __init__(self,search_path=None,platform=get_platform(),python=PY_MAJOR): File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/setuptools-0.6a9-py2.4.egg/pkg_resources.py", line 147, in get_platform version = _macosx_vers() File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/setuptools-0.6a9-py2.4.egg/pkg_resources.py", line 126, in _macosx_vers info = os.popen('/usr/bin/sw_vers').read().splitlines() exceptions.IOError: [Errno 4] Interrupted system call This seems to be caused by twisted's signal handling, which breaks os.popen (and subprocess), see this bug: http://twistedmatrix.com/bugs/issue733 I've attached a simple test script which triggers the problem (most of the time for me, you have to run it a few times as it doesn't always crash). I've got a work around though: If I import pkg_resources before starting my twisted app it seems to fix the problem. (I presume that get_platform's output is being kept somewhere, Environment's __init__ args I think.) cheers, Michael
At 04:59 PM 01/19/2006 +0000, Michael Twomey wrote:
I've got a work around though: If I import pkg_resources before starting my twisted app it seems to fix the problem. (I presume that get_platform's output is being kept somewhere, Environment's __init__ args I think.) cheers, Michae
Yes, in general it's best to import pkg_resources sooner rather than later. :) If you're running an application using a script generated by easy_install, this is taken care of for you, as pkg_resources gets imported in order to set up sys.path with the script's requirements.
participants (2)
-
Michael Twomey -
Phillip J. Eby