Simple change to not try and reimport handlers if they have failed previously.

This commit is contained in:
Ebag333
2017-03-15 15:53:40 -07:00
parent 8b124f3194
commit a588aec978

View File

@@ -32,6 +32,8 @@ except ImportError:
from logbook import Logger from logbook import Logger
pyfalog = Logger(__name__) pyfalog = Logger(__name__)
# Keep a list of handlers that fail to import so we don't keep trying repeatedly.
badHandlers = []
class Effect(EqBase): class Effect(EqBase):
@@ -159,34 +161,51 @@ class Effect(EqBase):
Grab the handler, type and runTime from the effect code if it exists, Grab the handler, type and runTime from the effect code if it exists,
if it doesn't, set dummy values and add a dummy handler if it doesn't, set dummy values and add a dummy handler
""" """
try: global badHandlers
self.__effectModule = effectModule = __import__('eos.effects.' + self.handlerName, fromlist=True)
self.__handler = getattr(effectModule, "handler", effectDummy)
self.__runTime = getattr(effectModule, "runTime", "normal")
self.__activeByDefault = getattr(effectModule, "activeByDefault", True)
t = getattr(effectModule, "type", None)
t = t if isinstance(t, tuple) or t is None else (t,) # Skip if we've tried to import before and failed
self.__type = t if self.handlerName not in badHandlers:
except (ImportError) as e: try:
# Effect probably doesn't exist, so create a dummy effect and flag it with a warning. self.__effectModule = effectModule = __import__('eos.effects.' + self.handlerName, fromlist=True)
self.__handler = getattr(effectModule, "handler", effectDummy)
self.__runTime = getattr(effectModule, "runTime", "normal")
self.__activeByDefault = getattr(effectModule, "activeByDefault", True)
t = getattr(effectModule, "type", None)
t = t if isinstance(t, tuple) or t is None else (t,)
self.__type = t
except (ImportError) as e:
# Effect probably doesn't exist, so create a dummy effect and flag it with a warning.
self.__handler = effectDummy
self.__runTime = "normal"
self.__activeByDefault = True
self.__type = None
pyfalog.debug("ImportError generating handler: {0}", e)
badHandlers.append(self.handlerName)
except (AttributeError) as e:
# Effect probably exists but there is an issue with it. Turn it into a dummy effect so we can continue, but flag it with an error.
self.__handler = effectDummy
self.__runTime = "normal"
self.__activeByDefault = True
self.__type = None
pyfalog.error("AttributeError generating handler: {0}", e)
badHandlers.append(self.handlerName)
except Exception as e:
self.__handler = effectDummy
self.__runTime = "normal"
self.__activeByDefault = True
self.__type = None
pyfalog.critical("Exception generating handler:")
pyfalog.critical(e)
badHandlers.append(self.handlerName)
self.__generated = True
else:
# We've already failed on this one, just pass a dummy effect back
self.__handler = effectDummy self.__handler = effectDummy
self.__runTime = "normal" self.__runTime = "normal"
self.__activeByDefault = True self.__activeByDefault = True
self.__type = None self.__type = None
pyfalog.warning("ImportError generating handler: {0}", e)
except (AttributeError) as e:
# Effect probably exists but there is an issue with it. Turn it into a dummy effect so we can continue, but flag it with an error.
self.__handler = effectDummy
self.__runTime = "normal"
self.__activeByDefault = True
self.__type = None
pyfalog.error("AttributeError generating handler: {0}", e)
except Exception as e:
pyfalog.critical("Exception generating handler:")
pyfalog.critical(e)
self.__generated = True
def getattr(self, key): def getattr(self, key):
if not self.__generated: if not self.__generated: