Skip to content

Commit 95ff1c1

Browse files
committed
progress.cpp: improve ipython detection
The Mitsuba Python bindings employ a custom logger that displays HTML (for colored status messages) and progress bars in Jupyter notebooks. This requires detecting whether the current program runs in a Jupyter notebook, which was not always reliably determined. This commit switches to a different detection method.
1 parent 4504654 commit 95ff1c1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/core/python/progress.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,16 @@ class JupyterNotebookAppender : public Appender {
119119
MI_PY_EXPORT(ProgressReporter) {
120120
/* Install a custom appender for log + progress messages if Mitsuba is
121121
* running within Jupyter notebook */
122-
nb::dict modules = nb::module_::import_("sys").attr("modules");
123-
if (!modules.contains("ipykernel"))
122+
try {
123+
nb::object ipython = nb::getattr(nb::builtins(), "get_ipython", nb::none());
124+
if (ipython.is(nb::none()))
125+
return;
126+
nb::object name = ipython().attr("__class__").attr("__name__");
127+
if (!name.equal(nb::str("ZMQInteractiveShell")))
128+
return;
129+
} catch (...) {
124130
return;
131+
}
125132

126133
Logger *logger = Thread::thread()->logger();
127134
logger->clear_appenders();

0 commit comments

Comments
 (0)