Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Log messages written from a helper thread appear in the wrong notebook cell (regression)

Đang mở
#1,491 1 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
58/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
jupyter, jupyter-notebook, python
Lĩnh vực
backend

Hướng nghiên cứu

Chạy ví dụ tối thiểu gồm ba ô với ipykernel 6.28.0 và 6.29.0, tập trung vào Logger.write_from_queue, Logger.log và sink sys.stderr. Theo dõi cách đầu ra từ luồng trợ giúp được liên kết với các ô của notebook. Được xem là hoàn tất khi các thông báo từ ô 3 và các ô sau đó xuất hiện trong ô tương ứng của chúng thay vì ô khởi tạo logger.

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

Mô tả

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.)

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

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 ipython/ipykernel

Tất cả issue của ipython/ipykernel

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.