shutdown function of logging module does not empty _loggers
還沒有人認領這個 Issue。
評估
研究方向
從 logging.py 第 213 行附近開始,使用 issue 中的程式碼重現該失敗。檢查 logging.shutdown() 如何處理 _loggers 和已關閉的處理常式,然後驗證在 shutdown 後重新使用 logger 可以新增新的 FileHandler 並輸出訊息,而不會出現 ValueError。
由索引模型根據 Issue 內容生成。
描述
if I want to reuse logger after call shutdown(), I can recreate log_a , add file_handler , but it will failure on log.xxx
Traceback (most recent call last): ... File "logging.py", line 141, in info File "logging.py", line 135, in log File "logging.py", line 71, in emit ValueError:
the root cause is, after execute logging.shutdown() , all logger remain in _loggers variables, so all handlers remain in logger.handlers, but the old file_handlers was closed, so emit method failure.
we can run follow code to verify it.
import logging
log_a = logging.getLogger('a')
log_a.setLevel(logging.DEBUG)
file_handler = logging.FileHandler('log.txt')
file_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
file_handler.setFormatter(formatter)
log_a.addHandler(file_handler)
log_a.debug('write to file')
print(logging._loggers)
print(log_a.handlers)
logging.shutdown()
log_a = logging.getLogger('a')
log_a.setLevel(logging.DEBUG)
file_handler = logging.FileHandler('log.txt')
file_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
file_handler.setFormatter(formatter)
log_a.addHandler(file_handler)
log_a.debug('write to file')
print(logging._loggers)
print(log_a.handlers)
to fixed it, pass name to pop method in line 213
logging._loggers.pop(logger.name, None)
- 主要語言
- Python
- 星號
- 2.9k
- 分支
- 1.1k
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
micropython/micropython-lib 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 62/100
micropython/micropython-lib#1074 ·
-
needs-info
難度 1/5 1 小時以內 新手友好度 72/100
micropython/micropython-lib#943 · 1 則留言 ·
-
"requests" does not handle redirection with relative path correctly可能重新可做 關聯的 PR 已關閉且未合併。 未關閉
難度 2/5 1-3 小時 新手友好度 68/100
micropython/micropython-lib#931 · 1 則留言 ·
-
難度 1/5 1 小時以內 新手友好度 62/100
micropython/micropython-lib#795 · 2 則留言 ·
-
webrepl: Support LAN as well as WLAN boards.可能已有人在做 @Romaric-RILLET 於 779 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 62/100
micropython/micropython-lib#762 ·
查看 micropython/micropython-lib 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 84/100
GoogleCloudPlatform/gce-rescue#195 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆
-
intake mcp-intake needs-ac needs-human-review priority:medium
難度 2/5 1-3 小時 新手友好度 67/100
Ikalus1988/MisakaNet#3848 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 75/100
521xueweihan/HelloGitHub#4105 ·
-
bug size:XS
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆