After taking a look at Django's source code, I see that Django stores the active language in the current thread.
In django.utils.translation.trans_real
:
_active = local()
...
def activate(language):
"""
Fetches the translation object for a given tuple of application name and
language and installs it as the current translation object for the current
thread.
"""
_active.value = translation(language)
This is all fine, but I'm not sure whether or not it's greenlet-safe ? I'm running Django with gunicorn, configured to run "green" gevent workers. Is local()
monkey-patched by gevent? Or is there a race-condition where a request might be served using another request's active language when using gevent?
Thanks.