From d0618d33c0a577f7e7281b29d3f04b31517dfc34 Mon Sep 17 00:00:00 2001 From: Luke Craig Date: Mon, 2 Sep 2024 13:09:43 -0400 Subject: [PATCH] pyplugins: alter unloading behavior wrt __main_loop_wait fixup slightly safer --- panda/python/core/pandare/panda.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/panda/python/core/pandare/panda.py b/panda/python/core/pandare/panda.py index da283abcea2..dbdcd2174a4 100644 --- a/panda/python/core/pandare/panda.py +++ b/panda/python/core/pandare/panda.py @@ -744,13 +744,23 @@ def unload_plugin(self, name): self.libpanda.panda_unload_plugin_by_name(name_ffi) def _unload_pyplugins(self): + ''' + Unload Python plugins first. + + We have to be careful to not remove __main_loop_wait because we're executing inside of __main_loop_wait and it more work to do + + We achieve this by first popping main loop wait and then re-adding it after unloading all other callbacks + ''' + mlw = self.registered_callbacks.pop("__main_loop_wait") + # First unload python plugins, should be safe to do anytime - while len(list(self.registered_callbacks)) > 0: + while self.registered_callbacks: try: self.delete_callback(list(self.registered_callbacks.keys())[0]) except IndexError: continue - #self.disable_callback(name) + + self.registered_callbacks["__main_loop_wait"] = mlw # Next, unload any pyplugins if hasattr(self, "_pyplugin_manager"):