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.
This commit is contained in:
John Colvin committed 2026-03-26 16:20:41 -04:00
1 parent 56445d2d66
commit a6c6e7faf3
1 file changed
+11 -1
@@ -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<function<void()>> 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(