Log messages written from a helper thread appear in the wrong notebook cell (regression)
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 58/100
調査の方向性
ipykernel 6.28.0 と 6.29.0 で最小の 3 セルの例を実行し、Logger.write_from_queue、Logger.log、および sys.stderr sink に注目してください。ヘルパースレッドからの出力がノートブックのセルにどのように関連付けられるかを追跡してください。完了条件は、セル 3 以降のセルからのメッセージが、logger の初期化セルではなく、それぞれのセルに表示されることです。
索引モデルが issue の本文から書いたものです。
説明
I recently found that, with some configurations, log messages emitted by Loguru would appear in the wrong Jupyter notebook cell: namely, the cell that initialized the logger, rather than the cell that was responsible for the log message. I opened Delgan/loguru#1427 to address this, but have since closed it, since the issue appears to be a regression in ipykernel, not in Loguru itself.
The problem appears for all versions of Loguru, but only for ipykernel >= 6.29. It is confined to the case where the logger is configured to write messages using a separate helper thread, which is useful when logging from multiple threads simultaneously. A minimal working example that illustrates the issue without the use of Loguru is the following:
(cell 1)
import sys
import multiprocessing
import threading
class Logger:
def __init__(self, sink):
self.sink = sink
self.queue = multiprocessing.SimpleQueue()
self.lock = threading.Lock()
self.thread = threading.Thread(target=self.write_from_queue, daemon=True)
self.thread.start()
def write_from_queue(self):
while True:
message = self.queue.get()
with self.lock:
self.sink.write(message)
def log(self, message):
self.queue.put(message)
(cell 2)
logger = Logger(sink=sys.stderr)
(cell 3)
logger.log("a message")
With ipykernel 6.28.0, the log message appears under cell 3, as intended, but with 6.29.0, it appears under cell 2 instead, and subsequent messages logged using the same logger will always appear under cell 2.
(Note: I tested with Jupyter Notebook 7.5.0 and Python 3.12.11 on Ubuntu 24.04.)
- 主要言語
- Python
- スター
- 734
- フォーク
- 411
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 9
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ipython/ipykernel のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 66/100
ipython/ipykernel の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main オープンarea: ci bug perceived difficulty: 3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ClickHouse/clickhouse-connect#1057 ·