Ticket #14894: trans_multithreading_fix.diff

File trans_multithreading_fix.diff, 1.4 KB (added by Maxim Bublis, 14 years ago)

Patch that fixes multithreading issue in translation

  • django/utils/translation/trans_real.py

     
    44import os
    55import re
    66import sys
     7import threading
    78import warnings
    89import gettext as gettext_module
    910from cStringIO import StringIO
     
    1718_translations = {}
    1819_active = {}
    1920
     21_translations_lock = threading.Lock()
     22
    2023# The default translation is based on the settings file.
    2124_default = None
    2225
     
    144147        # the same translation object (thus, merging en-us with a local update
    145148        # doesn't affect en-gb), even though they will both use the core "en"
    146149        # translation. So we have to subvert Python's internal gettext caching.
     150        _translations_lock.acquire()
    147151        base_lang = lambda x: x.split('-', 1)[0]
    148152        if base_lang(lang) in [base_lang(trans) for trans in _translations]:
    149153            res._info = res._info.copy()
     
    176180            if fallback is not None:
    177181                res = fallback
    178182            else:
     183                _translations_lock.release()
    179184                return gettext_module.NullTranslations()
    180185        _translations[lang] = res
     186        _translations_lock.release()
    181187        return res
    182188
    183189    default_translation = _fetch(settings.LANGUAGE_CODE)
Back to Top