[Chandler-dev] float('1.0') failing occasionally in French locale
Phillip J. Eby
pje at telecommunity.com
Wed Sep 13 08:45:28 PDT 2006
At 07:55 AM 9/13/2006 -0700, Jeffrey Harris wrote:
>Hi Folks,
>
>Bug 6688, "calendar threw an exception at least once when in the French
>locale", is assigned to me. I'm curious if anyone on the list has seen
>this behavior before.
>
>In the French locale, ',' should be used as a decimal point instead of
>'.'. But I've been operating under the (perhaps mistaken) impression
>that at least in Python 2.4, float() should be locale agnostic, and only
>locale.atof() should have trouble with '.' as a decimal point.
>
>So has Philippe found a bug in Python, or is there something else going
>on here?
Well, the tricky thing is that the function float() uses internally just
converts '.' to the locale-specific decimal point, then calls strtod() --
which is locale-specific.
Looking at the C source of the conversion function Python uses, it appears
as though *in theory* a race condition could occur, where the conversion
function gets the current locale, replaces the decimal point in the input
string, and then somebody in another thread *changes* the locale, such that
the converted string doesn't match. In other words, float() converts it to
a French float string, and then it sees a non-French locale when converting
it. Such an error would be incredibly difficult to reproduce, and it would
require that the other thread be running pure C or C++ code without holding
the GIL. I don't know if this is even remotely possible as a cause here,
though. We would need to have something like that running in a thread
somewhere, and I don't know if we do. And it would have to be switching
locale stuff around.
More information about the chandler-dev
mailing list