Use `PyObject_GetTypeData` without the GIL/attached thread state
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Feature or enhancement
Proposal:
In Cython we've historically let people do things like:
cdef class C:
cdef int non_object_attribute
def f(C c):
with nogil:
value = c.non_object_attribute
...
i.e. we've allowed them to get direct access into extension types without the GIL (providing they aren't manipulating Python objects).
When using PEP 697 lookup this becomes a little trickier because access to the attribute has to go through PyObject_GetTypeData. Looking at the implementation of PyObject_GetTypeData, it doesn't appear to need the GIL (except in debug mode where it sanity-checks the type).
I think I can work around this by calculating the offset of the struct myself once at startup (using PyObject_GetTypeData) and then doing all the lookups manually via the offset. It also looks like nanobind use a similar trick in places so I wouldn't be alone in this abuse of the system.
However, it'd be nice not to have to do this and if PyObject_GetTypeData could somehow be exempted from the "C API needs the GIL" rule.
I do understand that people would probably prefer not to do this, so I'm happy to look at other options.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
I asked about this in https://discuss.python.org/t/does-pyobject-gettypedata-need-the-gil/104637/4 - it only generated a small amount of discussion.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず PyObject_GetTypeData の実装と、GIL が必要かどうかについてのリンク先の Discourse の議論を読みます。PEP 697 の属性アクセスについて、サポートされている GIL なしのアプローチが可能かどうかを判断し、Cython ユーザー向けに明確な結論または代替案を文書化します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, python
- 領域
- api
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 32/100