Code to reproduce
from core import echo_console
from events import Event
@Event('player_jump')
def on_player_jump(game_event):
echo_console("Player has jumped")
raise Exception("Too bad. But no.")
Result
] sp load autounloadtest
[SP] Loading plugin 'autounloadtest'...
[SP] Caught an Exception:
Traceback (most recent call last):
File '..\addons\source-python\packages\source-python\plugins\manager.py', line 71, in __missing__
instance = self.instance(plugin_name, self.base_import)
File '..\addons\source-python\packages\source-python\plugins\instance.py', line 82, in __init__
self._plugin = import_module(import_name)
File '..\addons\source-python\plugins\autounloadtest\autounloadtest.py', line 10, in <module>
raise Exception('Too bad. But no.')
Exception: Too bad. But no.
[SP] Plugin 'autounloadtest' was unable to be loaded.
But the Event is still registered, e.g. if you jump, it will print Player has jumped to the console.
Additionaly, I looked through load_and_unload branch, and did not find any mechanism to prevent this either.
Possible solution
As we don't have access to the globals of the plugin (because it was unable to load) and can't really iter over them to hunt AutoUnload instances, it maybe worth just checking the difference between a set of existing AutoUnload instances before plugin was trying to load, and a set of existing AutoUnload instances after the plugin was loaded or failed to load.
This way we will recognize new AutoUnload instances even if they were created by the failing plugin.
Code to reproduce
Result
But the Event is still registered, e.g. if you jump, it will print
Player has jumpedto the console.Additionaly, I looked through load_and_unload branch, and did not find any mechanism to prevent this either.
Possible solution
As we don't have access to the globals of the plugin (because it was unable to load) and can't really iter over them to hunt
AutoUnloadinstances, it maybe worth just checking the difference between a set of existingAutoUnloadinstances before plugin was trying to load, and a set of existingAutoUnloadinstances after the plugin was loaded or failed to load.This way we will recognize new
AutoUnloadinstances even if they were created by the failing plugin.