raising resource warnings prevents resource cleanup

オープン
#94,900 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
backend

調査の方向性

リンク先の行にある Lib/asyncio/unix_events.py から始め、リソースのクリーンアップ前に ResourceWarning が発行される他の箇所を探します。影響を受けるクリーンアップパスを -Werror または filterwarnings=['error', ...] で実行します。警告のエスカレーションによって基盤となるリソースが閉じられなくなることがなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

stdlib type-bug

Bug report
in a number of places a ResourceWarning is issued before cleaning up a resource eg
https://github.com/python/cpython/blob/944ff8c57c9e8ff5a5bd18925070ddb1504490ab/Lib/asyncio/unix_events.py#L559-L562
normally this is fine - however if you're running with -Werror these warnings are raised as exceptions and so prevent the underlying resource from being cleaned up. This is in particular a problem when running a test suite with filterwarnings=['error', ... where resource cleanup can be delayed for many tests.

I think these should instead be restructured as:

 def __del__(self, _warn=warnings.warn): 
     if self._pipe is not None: 
         msg = f"unclosed transport {self!r}"  # grab the repr before closing the pipe so it displays as "open" still
         self._pipe.close()
         _warn(msg, ResourceWarning, source=self)  # issue the warning after closing the resource

Your environment

  • CPython versions tested on:
  • Operating system and architecture:
主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。