Skip to content

Commit bb744e9

Browse files
author
ny
committed
optimize unload module
1 parent 2badf7d commit bb744e9

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

FFxivPythonTrigger/FFxivPythonTrigger.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ def reload_module(module):
252252
if sub_module.startswith(module_name):
253253
try:
254254
reload(import_module(sub_module))
255-
except ModuleNotFoundError:
256-
continue
255+
except Exception:
256+
del sys.modules[sub_module]
257257
for plugin in register_module(import_module(module_name)):
258258
plugin.p_start()
259259

@@ -303,13 +303,14 @@ def _process_event(event: EventBase):
303303

304304

305305
def unload_plugin(plugin_name):
306-
_logger.debug("unregister plugin [start]: %s" % plugin_name)
307-
try:
308-
_plugins[plugin_name].p_unload()
309-
del _plugins[plugin_name]
310-
_logger.info("unregister plugin [success]: %s" % plugin_name)
311-
except Exception:
312-
_logger.error('error occurred during unload plugin\n %s' % format_exc())
306+
if plugin_name in _plugins:
307+
_logger.debug("unregister plugin [start]: %s" % plugin_name)
308+
try:
309+
_plugins[plugin_name].p_unload()
310+
del _plugins[plugin_name]
311+
_logger.info("unregister plugin [success]: %s" % plugin_name)
312+
except Exception:
313+
_logger.error('error occurred during unload plugin\n %s' % format_exc())
313314

314315

315316
def list_plugin_names():

0 commit comments

Comments
 (0)