You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Log messages written from a helper thread appear in the wrong notebook cell (regression) #1491
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:
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.)
Current main routes this correctly on standard CPython 3.12 after #1451, but the same failure remains when a new thread inherits the caller context (the default on free-threaded CPython): the inherited parent header pins later output to the logger-initialization cell. Reproduced with a live kernel; I have a focused regression and fix ready that ignores inherited thread-local parents unless they were set in the current thread.
Activity
emecii commentedon Sep 10, 2026
Current
mainroutes this correctly on standard CPython 3.12 after #1451, but the same failure remains when a new thread inherits the caller context (the default on free-threaded CPython): the inherited parent header pins later output to the logger-initialization cell. Reproduced with a live kernel; I have a focused regression and fix ready that ignores inherited thread-local parents unless they were set in the current thread.Fix output routing when threads inherit context (#1559)