logging.captureWarnings(True) doesn't show object allocation (-X tracemalloc)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
So sánh việc xây dựng WarningMessage trong Lib/warnings.py với cách xử lý tương ứng trong Python/_warnings.c, sau đó chạy lệnh repro.py được cung cấp với -X tracemalloc=5. Được xem là hoàn tất khi các cảnh báo được định tuyến qua logging.captureWarnings(True) vẫn giữ lại traceback phân bổ đối tượng được hiển thị cho các cảnh báo chưa được bắt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug report
When using logging.captureWarnings(True), the information about object allocation that you should get with -X tracemalloc gets lost.
It appears to be a discrepancy between Python and C implementation of the warnings module? source isn't passed to the created WarningMessage object in the Lib/warnings.py:
https://github.com/python/cpython/blob/a17cd47b614f8bc660788647a009a25e121221d7/Lib/warnings.py#L12
https://github.com/python/cpython/blob/a17cd47b614f8bc660788647a009a25e121221d7/Lib/warnings.py#L17
https://github.com/python/cpython/blob/a17cd47b614f8bc660788647a009a25e121221d7/Lib/warnings.py#L394
while it is in Python/_warnings.c:
https://github.com/python/cpython/blob/a17cd47b614f8bc660788647a009a25e121221d7/Python/_warnings.c#L593-L605
Reproduction steps:
- Create a file
repro.pywith contents:
import logging
import tempfile
import warnings
warnings.simplefilter("default", category=ResourceWarning)
logging.basicConfig()
print("--- UNCAPTURED WARNING ---")
file = tempfile.SpooledTemporaryFile(1)
file.write(b"foo")
file = None
print("\n--- CAPTURED WARNING ---")
logging.captureWarnings(True)
file = tempfile.SpooledTemporaryFile(1)
file.write(b"foo")
file = None
- Run
python -X tracemalloc=5 - See that output only contains object allocation traceback for uncaptured warning:
--- UNCAPTURED WARNING ---
/tmp/test_tracemallo/repro.py:12: ResourceWarning: unclosed file <_io.BufferedRandom name=3>
file = None
Object allocated at (most recent call last):
File "/tmp/test_tracemallo/repro.py", lineno 11
file.write(b"foo")
File "/usr/lib/python3.10/tempfile.py", lineno 911
self._check(file)
File "/usr/lib/python3.10/tempfile.py", lineno 807
self.rollover()
File "/usr/lib/python3.10/tempfile.py", lineno 812
newfile = self._file = TemporaryFile(**self._TemporaryFileArgs)
File "/usr/lib/python3.10/tempfile.py", lineno 760
return _io.open(fd, mode, buffering=buffering,
--- CAPTURED WARNING ---
WARNING:py.warnings:/tmp/test_tracemallo/repro.py:18: ResourceWarning: unclosed file <_io.BufferedRandom name=3>
file = None
Your environment
- CPython versions tested on: 3.7.13, 3.8.13, 3.9.13 (installed from deadsnakes ppa), 3.10.4 (system Python)
- Operating system and architecture: Ubuntu 22.04
Linked PRs
- gh-111451
- 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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/cpython
-
docs pending
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
build type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
stdlib topic-email type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Tất cả issue của python/cpython
Issue tương tự
-
🐛 Bug 🔔 Pending processing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·