0

Django のソース コードを調べたところ、Django がアクティブな言語を現在のスレッドに格納していることがわかります。

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)    

これで問題ありませんが、greenlet-safe かどうかはわかりません。「グリーン」geventワーカーを実行するように構成されたgunicornでDjangoを実行しています。geventlocal()によってモンキー パッチが適用されますか? または、gevent を使用しているときに別のリクエストのアクティブな言語を使用してリクエストが処理される可能性があるという競合状態はありますか?

ありがとう。

4

1 に答える 1

2

気にしないでください、私はgevent のドキュメントで答えを見つけました: thread-local storage is monkey-patched by gevent で、 greenlet-local storage になります。したがって、すべてが安全でなければなりません。

詳細は次のとおりです。

  • gevent のpatch_thread()関数は、threadおよびthreadingモジュールにパッチを適用します。これには、スレッド ローカル ストレージを greenlet ローカル ストレージにするためのパッチが含まれます。
  • gevent のpatch_all()関数呼び出しpatch_thread().
  • gunicorn はpatch_all()、gevent ワーカーを開始するときに gevent の関数を呼び出します。
于 2013-04-07T09:44:45.053 に答える