locale module & threads (was Re: I feel stoopid ... this code is to verbose)

jepler at unpythonic.net jepler at unpythonic.net
Mon Jun 17 07:53:52 EDT 2002


On Mon, Jun 17, 2002 at 09:37:00AM +0200, Max M wrote:
> "setlocale() is not thread safe on most systems. Applications typically 
> start with a call of::
[...]

Since the locale.format and ._group are written in Python, you could have
taken their code and rewritten them to not use the system locale, but
your values of grouping, thousands_sep, and decimal_point.

This is actually an interesting question.  I can certainly see the use of
having a web application that prepares a different locale for each user,
and where multiple simultaneous requests might run in different threads.
It seems that in such situations, it might be valuable for Python to
provide some sort of threadsafe locale support.

Is there something about this situation I'm missing?  It's bound to hurt
performance if every locale.format() / locale.gettext() call has to take a
lock.

Jeff





More information about the Python-list mailing list