Memory leak: warnings module

Đang mở
#97,557 9 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
devtools

Hướng nghiên cứu

Bắt đầu bằng cách chạy script được cung cấp memory_leak_warnings.py trong lệnh Docker python:3.9 và theo dõi nó bằng docker stats. Đọc tài liệu của module warnings và so sánh hành vi giữa các phiên bản CPython được báo cáo. Issue không xác định một bản sửa lỗi cụ thể hay một bài kiểm tra hoàn thành rõ ràng nào ngoài việc ngăn bộ nhớ tăng không giới hạn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
558

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/cpython

Tất cả issue của python/cpython

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.