﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14894	translation is not threadsafe	Maxim Bublis	Sergey Kolosov	"I've got the following error in my multithreading application:
{{{
Traceback (most recent call last):
 File ""/usr/local/lib/python2.6/site-packages/django/core/handlers/base.py"", line 80, in get_response
   response = middleware_method(request)
 File ""/usr/local/lib/python2.6/site-packages/django/middleware/locale.py"", line 17, in process_request
   translation.activate(language)
 File ""/usr/local/lib/python2.6/site-packages/django/utils/translation/__init__.py"", line 66, in activate
   return real_activate(language)
 File ""/usr/local/lib/python2.6/site-packages/django/utils/functional.py"", line 55, in _curried
   return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
 File ""/usr/local/lib/python2.6/site-packages/django/utils/translation/__init__.py"", line 36, in delayed_loader
   return getattr(trans, real_name)(*args, **kwargs)
 File ""/usr/local/lib/python2.6/site-packages/django/utils/translation/trans_real.py"", line 193, in activate
   _active[currentThread()] = translation(language)
 File ""/usr/local/lib/python2.6/site-packages/django/utils/translation/trans_real.py"", line 177, in translation
   current_translation = _fetch(language, fallback=default_translation)
 File ""/usr/local/lib/python2.6/site-packages/django/utils/translation/trans_real.py"", line 141, in _fetch
   if base_lang(lang) in [base_lang(trans) for trans in _translations]:

RuntimeError: dictionary changed size during iteration
}}}

The reason is not threadsafe global _translations dictionary in django.utils.translation.trans_real module. In one thread you could iterate [http://code.djangoproject.com/browser/django/trunk/django/utils/translation/trans_real.py#L148 over it] and change it [http://code.djangoproject.com/browser/django/trunk/django/utils/translation/trans_real.py#L180 in another one], that could lead to the above RuntimeError.

Patch attached."	Bug	closed	Internationalization	1.4	Normal	fixed	threadsafety translation	botondus@… chris@…	Accepted	1	0	1	1	0	0
