Skip to content

Commit

Permalink
pyplugins: alter unloading behavior wrt __main_loop_wait
Browse files Browse the repository at this point in the history
fixup

slightly safer
  • Loading branch information
lacraig2 committed Sep 2, 2024
1 parent 7d91382 commit 2888c39
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions panda/python/core/pandare/panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down

0 comments on commit 2888c39

Please sign in to comment.