瀏覽代碼

Fix lazy module behavior after failure.

tags/v0.2
Ben Kurtovic 10 年之前
父節點
當前提交
e88d1c2c70
共有 1 個文件被更改,包括 11 次插入1 次删除
  1. +11
    -1
      earwigbot/lazy.py

+ 11
- 1
earwigbot/lazy.py 查看文件

@@ -36,11 +36,21 @@ __all__ = ["LazyImporter"]

_real_get = ModuleType.__getattribute__

def _create_failing_get(exc):
def _fail(self, attr):
raise exc
return _fail

def _mock_get(self, attr):
with _real_get(self, "_lock"):
if _real_get(self, "_unloaded"):
type(self)._unloaded = False
reload(self)
try:
reload(self)
except ImportError as exc:
type(self).__getattribute__ = _create_failing_get(exc)
del type(self)._lock
raise
type(self).__getattribute__ = _real_get
del type(self)._lock
return _real_get(self, attr)


Loading…
取消
儲存