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(