From a6c6e7faf3fe8bf30c9fe9e9933ec1c5065bbcd4 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 17 Mar 2026 16:05:37 +0000 Subject: [PATCH] improve: Wait until py work requested before loading py modules So we don't crash due to missing py modules when no py plugins are running. --- .../python_interop/plugin_manager.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib_python_interop/python_interop/plugin_manager.cpp b/src/lib_python_interop/python_interop/plugin_manager.cpp index c4864a339..07caebc49 100644 --- a/src/lib_python_interop/python_interop/plugin_manager.cpp +++ b/src/lib_python_interop/python_interop/plugin_manager.cpp @@ -99,6 +99,15 @@ struct __attribute__((visibility("hidden"))) PluginManager_Impl { session_data = &sd; mx.unlock(); try { + // Wait for work_req before spinning up the python interpreter. This makes it so, if no + // python plugins are enabled, we don't needlessly crash due to missing py modules. + optional> work_req; + while (keep_going) { + work_req = work_queue.wait_until_pop(); + if (work_req) { + break; + } + } sd.import("sys").attr("path").attr("insert")( 0, "python_interop_plugins"); sd.import("spark_core").attr("configure_default_logger")(); @@ -110,8 +119,8 @@ struct __attribute__((visibility("hidden"))) PluginManager_Impl { Stopwatch sw; int n = 0; while (keep_going) { - auto work_req = work_queue.wait_until_pop(); if (!work_req) { + work_req = work_queue.wait_until_pop(); continue; } LOG_INVOKING(n); @@ -122,6 +131,7 @@ struct __attribute__((visibility("hidden"))) PluginManager_Impl { } LOG_INVOKED(n, sw.elapsed()); n++; + work_req = std::nullopt; } } catch (const std::exception &ex) { bts_assert_msgf(