`atexit` module breaks refleak check
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
If the test registers a callback with atexit module, refleak test will consider it a leak.
def test_refleak(self):
atexit.register(lambda: None)
This is the root cause of the buildbot failure of https://github.com/python/cpython/pull/139185. It's a couple of coincidences that caused the seemingly unrelated issue. Basically, clearing the module cache in test_zipimport made the module-level code in rlcompleter, which includes a register to atexit, run more than once.
There are a few possible approaches to fix this, but I did not find the solution that I'm immediately happy with.
I consider this a test framework bug as this should be a valid behavior. The ideal solution is to keep the atexit callbacks before running test in a loop and restore it after. However, atexit does not provide such an interface, public or private. You can either clear it or run it. The callbacks are stored in a state of the interpreter and we don't have any access to it.
Without that, we either need to somehow calculate the allocated memory by atexit, or hope that no one writes a test that writes to atexit. Of course there might be other ways that I did not think of.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-139305
- gh-139357
- [3.14] gh-139305 was backported as part of gh-139280
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
refleak テストフレームワークと、atexit コールバックを登録する test_refleak の例から始めます。test_zipimport がモジュールキャッシュをクリアすることで、rlcompleter のモジュールレベルの登録が繰り返し実行される仕組みを調査し、既存の作業についてリンク先の PR gh-139305 と gh-139357 を確認します。完了条件は、有効な atexit 登録が refleak として表示されなくなることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- testing-qa
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 20/100