This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: imp.load_module in thread causes core dump on OSX 10.6
Type: Stage:
Components: Extension Modules, Interpreter Core, macOS Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ronaldoussoren Nosy List: dohertywa, peterhunt, ronaldoussoren
Priority: normal Keywords:

Created on 2009-10-15 19:35 by peterhunt, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg94106 - (view) Author: Pete Hunt (peterhunt) Date: 2009-10-15 19:35
Apologies if I mess up the formatting - my first bug report submitted.

Steps to reproduce (OSX Snow Leopard, 2.6.3)

>>> import threading, imp
>>> def doit():
...     print imp.load_module("cherrypy", None, 
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-
packages/CherryPy-3.1.2-py2.6.egg/cherrypy", ('', '', 5))
... 
>>> threading.Thread(target=doit).start()
>>> Trace/BPT trap
msg94107 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2009-10-15 19:41
This seems to be a known issue: importing extensions in a thread fails on 
OSX 10.6 (with a hard crash of the interpreter). The crash in inside the 
initialisation function for an Apple framework. 

I haven't been able to determine if the problem is in Python or OSX, 
although it likely is a problem in the OS and is definitely a regression 
in OSX (it works on 10.5 but crashes on 10.6).
msg94899 - (view) Author: Adam Doherty (dohertywa) Date: 2009-11-04 18:28
Hello:

Having the same issues in a web app I've written. Tested with the
default 2.5 and 2.6 on Snow Leopard and 2.5 on Ubuntu 8.04 (no problems
under Linux)  Replaced the default Python with 2.6.4 from python.org, my
app no longer crashes.

Hope it helps.
msg95390 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2009-11-17 16:47
The crash is caused by loading any extension that happens to link with 
CoreFoundation on a secondary thread, unless CoreFoundation was already 
initialized.

The CF framework contains a constructor that explicitly aborts when it 
is not called on the main thread (all of this on Snow Leopard only).

I've found a workaround for this issue: ensure that Python is linked to 
the CoreFoundation framework, that way CF will be initialized when 
Python starts.

I'm working on a clean patch for this
msg95499 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2009-11-19 17:31
I've just committed a fix for this issue in all 4 active branches (2.6, 
2.7, 3.1 and 3.2)
History
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51393
2009-11-19 17:31:05ronaldoussorensetstatus: open -> closed
resolution: fixed
messages: + msg95499
2009-11-17 16:47:29ronaldoussorensetmessages: + msg95390
2009-11-04 18:28:43dohertywasetnosy: + dohertywa
messages: + msg94899
2009-10-15 19:41:02ronaldoussorensetmessages: + msg94107
2009-10-15 19:35:20peterhuntcreate