Building Python 2.7.1 on Mac OS X, import threading and a KeyError Exception

1

Original Problem:

I am building Python 2.7.1 on Mac OS X 10.6.7 and am having issues with a KeyError exception being thrown from the threading module when Python is quit (likely on the atexit call).

I haven't been able to find a proper answer anywhere, and am wondering if someone here knows what the issue may be and how to perhaps compile/configure Python correctly in order to avoid this.

The steps to produce the error is relatively short:

echo "import threading" | ./python

This produces the following output:

Exception KeyError: KeyError(140735086161056,) in <module 'threading' from '/Users/danerik/quantumnotes/qw-control/quantumsource/external-libs/build/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.pyc'> ignored

The error is in all likelihood harmless (I have experienced no ill effects), but the message is undesirable and I would prefer it not be there.

Dan

Posted 2011-06-10T20:48:38.223

Reputation: 111

Answers

0

The problem I experienced was that I had a custom Modules/main.c file from an older Python release (2.6.1) polluting my 2.7.1 release. Although nearly identical, the main difference is that in the 2.6.1 main.c file there was a WaitForThreadShutdown(void) routine that would perform operations if the threading module had been imported. A new custom Modules/main.c file was then made based on the new 2.7.1 release, and this solved my issue.

My bad.

Dan

Posted 2011-06-10T20:48:38.223

Reputation: 111

0

The build of python2.7 from MacPorts to doesn't have that problem. You could just get it from them, or try comparing your configure flags to theirs and see what differs.

blahdiblah

Posted 2011-06-10T20:48:38.223

Reputation: 3 125

The build from Homebrew also doesn't suffer this... I've been looking at their build flags, and can't seem to find differences in their configure script. Perhaps I'm overlooking something... – Dan – 2011-06-10T21:10:48.750

I figured out my problem - it was an issue of a version mismatch in the Modules/main.c file. I was mixing 2.6.1 code with 2.7.1 code. – Dan – 2011-06-10T22:15:15.233

@Dan Glad to hear it. I see that you edited your question to include the fix too. Around here it would be more natural to add the solution as an answer and then mark it "accepted" rather than making it part of the question. – blahdiblah – 2011-06-10T22:17:58.260

Alright - I'll do that. Thanks for tip! It'll have to wait a bit - as I'm under 100 in reputation, I can first self-answer in 6 hours :) – Dan – 2011-06-10T22:22:46.280