Pythonの運営評議会は、global interpreter lockの廃止をどう決定したのか

Pythonの仕様はPEP(Python Enhanced Propozal)、つまりPythonの仕様を拡張するための仕様を誰かが提起し、それをSteering Council(運営評議会)が決定することでPythonそのものに盛り込まれる。インターネットの仕様に詳しい人であれば、RFCみたいなものといえば伝わるだろうか。

ちなみに、昔からそうだったというわけではなく、それまでPythonの生みの親であるGuido van Rossumが一人で決めていたのが、2019年に引退を機に現在の運営体制になっており、その際の議論は、こちらに書いた。

で、とあるPEPを調べていたら、どうやらPEP703に関する議論が盛り上がってることに目が留まった。

CPython’s global interpreter lock (“GIL”) prevents multiple threads from executing Python code at the same time. The GIL is an obstacle to using multi-core CPUs from Python efficiently. This PEP proposes adding a build configuration (--disable-gil) to CPython to let it run Python code without the global interpreter lock and with the necessary changes needed to make the interpreter thread-safe.

GILというのは、Pythonが同時に1つのスレッドしか動かせないようにするという仕組み。この仕組みがあることで、特にAIの分野で使われているライブラリなどを並列処理できないという問題があると言われている。

PEPは本来は技術的なことが書かれている文書なのだが、PEP703は、その話にたどり着くまでの前置きがめちゃくちゃ長い。AlphaGoで有名なDeepMind社のエンジニアや、scikit-learn、NumPy、PyTorchなどのライブラリの作者の発言などが盛り込まれている。多くの開発者がPythonから離れてしまうのではないかという危惧が伝わってくる。

一方で、このGILを無効にできるようにするためには、あちらこちらで手を入れなければいけないし、Python自体にリスクを抱える可能性もある。そこで運営評議会の出番というわけだ。

The concept of making Python free-threaded, regardless of the practical implementation such as removing the GIL, has a lot of unknowns. We don’t know how much code implicitly relies on the GIL, or is thread-unsafe in subtle ways that are masked by the GIL. We don’t know how much work it’s going to be to deal with the fallout of introducing free-threading (regardless of how that occurs). Do you think gaining free-threading is worth this uncertainty (and the uncertain amount of work to the Core Devs and the Python community)?

5人の評議会メンバーのうちの一人であるBrett Cannon氏が100人ほどいるコア開発者へ「多くのunknown(未知数)がある」という状況で、2つの質問を投げている。

一つ目は、そもそも議論する必要があるだろうかという質問で46人が投票し、84パーセントの開発者がYesと答えている。

もう一つの質問は、コア開発者に対しPEP703をサポートしたいかという質問だ。こちらは回答者が38人に減り、63パーセント、つまり24人がサポートしたいと答えている。

コア開発者が100人いる中で24人というのは多いか少ないかわからないが、この投票結果を踏まえ、再び運営評議会メンバーの別の人物が、決定事項を通知している。

Thank you, everyone, for responding to the poll on the no-GIL proposal . It’s clear that the overall sentiment is positive, both for the general idea and for PEP 703 specifically. The Steering Council is also largely positive on both. We intend to accept PEP 703, although we’re still working on the acceptance details.

大部分がpositive(肯定的)なので、PEP703を受け入れるという考えのようだ。いろいろ読んでみると、PythonがGILありとGILなしで分断しないための配慮など、考えることは山積みのようだが、3.13、つまり現在の最新版は3.11だから次の次のリリースで実験的に盛り込むのだという。

これだけ世界中に影響を与えそうな決定だからこそ、有力なライブラリ作者のコメントなどを列挙し、未知数があることを伝えたうえで投票するなどしているのだろう。個人的には投票を仕切っている人物とは別の人物が決定事項を通知しているのも、運営評議会ノウハウなんじゃないかと思ってみている。



この記事が気に入ったらサポートをしてみませんか?