classification
Title: strptime problem
Type: crash Stage:
Components: Macintosh Versions: Python 2.7, Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ronaldoussoren Nosy List: brett.cannon, kakacek, ned.deily, ronaldoussoren (4)
Priority: Keywords

Created on 2009-10-08 22:48 by kakacek, last changed 2009-11-19 17:30 by ronaldoussoren.

Files
File name Uploaded Description Edit Remove
Python_2009-10-08-204652_fimt-3.crash ned.deily, 2009-10-09 03:57
Messages (8)
msg93765 - (view) Author: Jiri Krivanek (kakacek) Date: 2009-10-08 22:48
The following simple code works perfectly on W2K, WXP, Ubuntu, OSX10.4 
OSX10.5. It, however, stopped working on OSX10.6 (Snow Leopard): It 
simply crashes. It is a strptime() which causes problems to me.

Any idea? Any workaround?

import time
import thread

def test():
    print "TS: "
    print "%s" % str(time.strptime("2009-09-09 16-56-37", "%Y-%m-%d %H-
%M-%S"))
    
thread.start_new_thread (test, ())
time.sleep(2.0)
msg93773 - (view) Author: Ned Deily (ned.deily) Date: 2009-10-09 03:57
It fails for me as well on 10.6 (Intel) with 2.6 and trunk and did not 
fail on 10.5 (ppc). time.strptime does an import of a python module from C 
code so, not surprisingly, adding a time.strptime call in the main module 
prior to the thread.start_new_thread avoids the crash.

Attached is the stack trace of the crash with 2.6.4rc1.
msg93774 - (view) Author: Jiri Krivanek (kakacek) Date: 2009-10-09 04:58
The suggested workaround helped to solve the issue to me. Thank for it 
very much.

I am using Python 2.4.4 and cannot upgrade to anything above 2.4 due to 
incompatibility between .pyc files (I have tenths of production sites with 
Python 2.4.4, with automatic update feature, onto which I only populate 
the .pyc files only, so upgrading to Python 2.5.x+ would cause all my 
sites to crash upon the next automatic update).

Consequently, from my perspective, this issue is solved and may be closed.
msg93775 - (view) Author: Brett Cannon (brett.cannon) Date: 2009-10-09 05:23
It's confirmed on 2.5 - trunk, but it is not an issue in at least 3.1 and 
py3k.

As Ned pointed out, time imports _strptime.py from the standard library 
which is known to be a no-no. But still, it's odd that it crashed on Snow 
Leopard but not Leopard. I will leave this issue open for Ronald to make a 
call as to whether this is a Python issue or not as Python is dying in 
__CFInitialize().
msg93868 - (view) Author: Ronald Oussoren (ronaldoussoren) Date: 2009-10-11 18:09
The crash happens whenever you import code on a secondairy thread.

I consider this a platform bug in the implementation of dlopen, because 
the crash also occurs with this variant on test():

def test():
    print "DL"
    p = os.path.join(os.path.dirname(time.__file__), '_locale.so')
    m = dl.open(p)
    print m

(Don't forget to import dl and os before running the code).

I'm investigating a workaround.
msg95380 - (view) Author: Ronald Oussoren (ronaldoussoren) Date: 2009-11-17 10:58
FWIW, I've filed an issue with Apple for this: Radar #7330231
msg95391 - (view) Author: Ronald Oussoren (ronaldoussoren) Date: 2009-11-17 16:49
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.
msg95498 - (view) Author: Ronald Oussoren (ronaldoussoren) Date: 2009-11-19 17:30
I committed a fix in r76403 (trunk), r76404 (2.6), r76405 (3.2), 76406 
(3.1)
History
Date User Action Args
2009-11-19 17:30:19ronaldoussorensetstatus: open -> closed
resolution: fixed
messages: + msg95498
2009-11-17 16:49:54ronaldoussorensetmessages: + msg95391
2009-11-17 10:58:07ronaldoussorensetmessages: + msg95380
2009-10-11 18:09:36ronaldoussorensetmessages: + msg93868
2009-10-09 05:23:12brett.cannonsetnosy: + brett.cannon

messages: + msg93775
versions: + Python 2.5
2009-10-09 04:58:13kakaceksetmessages: + msg93774
2009-10-09 03:57:08ned.deilysetfiles: + Python_2009-10-08-204652_fimt-3.crash
versions: + Python 2.6, Python 2.7, - Python 2.4
nosy: + ned.deily

messages: + msg93773
2009-10-08 22:48:50kakacekcreate