Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#1,491 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
jupyter, jupyter-notebook, python
Ambito
backend

Direzione di ricerca

Esegui l'esempio minimo a tre celle con ipykernel 6.28.0 e 6.29.0, concentrandoti su Logger.write_from_queue, Logger.log e sul sink sys.stderr. Traccia il modo in cui l'output del thread helper viene associato alle celle del notebook. Il lavoro è completato quando i messaggi della cella 3 e delle celle successive compaiono nella cella di competenza anziché nella cella di inizializzazione del logger.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
734
Fork
411
Merge medio
1g 2h
PR unite (30g)
9

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ipython/ipykernel

Tutte le issue di ipython/ipykernel

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.