diff --git a/panda/python/core/pandare/pypluginmanager.py b/panda/python/core/pandare/pypluginmanager.py index 82a8556d2f5..9b7181ef98c 100644 --- a/panda/python/core/pandare/pypluginmanager.py +++ b/panda/python/core/pandare/pypluginmanager.py @@ -5,6 +5,7 @@ """ from pathlib import Path from pandare import PyPlugin +import datetime import inspect import importlib.util @@ -197,6 +198,7 @@ def load(self, pluginclasses, args=None, template_dir=None): self.plugins[name].__preinit__(self, args) self.get_ppp_funcs(self.plugins[name]) self.plugins[name].__init__(self.panda) + self.plugins[name].load_time = datetime.datetime.now() # Setup webserver if necessary if self.flask and hasattr(self.plugins[name], 'webserver_init') and \ @@ -272,8 +274,10 @@ def unload_all(self): ''' Unload all PyPlugins ''' - while self.plugins: - name, cls = self.plugins.popitem() + # unload in reverse order of load time + plugin_list = {k:v for k,v in reversed(sorted(self.plugins.items(), key=lambda x: x[1].load_time))} + while plugin_list: + name, cls = plugin_list.popitem() self.unload(cls, do_del=False) def is_loaded(self, pluginclass):