Memory leak: warnings module

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
python
領域
devtools

調査の方向性

まず、提供されているスクリプト memory_leak_warnings.py を Docker コマンド python:3.9 で実行し、docker stats で監視します。warnings モジュールのドキュメントを読み、報告されている CPython バージョン間で動作を比較します。この issue では、メモリが際限なく増加するのを防ぐこと以外に、具体的な修正方法や明確な完了テストは定義されていません。

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

説明

interpreter-core type-bug

Bug report

Memory leak in warnings module
Steps to reproduce:

  1. Create test script
    `$ cat > memory_leak_warnings.py << EOF
    import warnings
    import random

while True:
warn_text = str(random.random())
warnings.warn(warn_text, DeprecationWarning)
EOF`

  1. Run script
    docker run -it --rm --name memory-leak-warnings -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3.9 python memory_leak_warnings.py

  2. Monitor memory usage of container with running script
    $ docker stats memory-leak-warnings

And you can see MEM USAGE constantly increased
Screenshot from 2022-09-26 10-48-45

https://docs.python.org/3/library/warnings.html
Warnings is a standard module, anyone can use it.
Having an application with a lot of dependencies - you have no idea which module use warnings module, so in production you will have memory leak.
For example aiomysql use it https://github.com/aio-libs/aiomysql/blob/master/aiomysql/cursors.py#L479 and seems like it is ok to use warnings standard module.

I have to disable warnings to get rid such kind of memory leaks. Is it ok? Or maybe warnings must be disabled on production enviroments? If so - this should be noticed in documentaion.

Thanks

Your environment

主要言語
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 を短くまとめたダイジェスト。