commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

r5583 - trunk/gnue-common/src/apps


From: reinhard
Subject: r5583 - trunk/gnue-common/src/apps
Date: Tue, 30 Mar 2004 16:50:54 -0600 (CST)

Author: reinhard
Date: 2004-03-30 16:50:53 -0600 (Tue, 30 Mar 2004)
New Revision: 5583

Modified:
   trunk/gnue-common/src/apps/plugin.py
Log:
Attempt to import any plugin only once.  Module initialization code is only
executed once, even if it fails with an exception.  So a second attempt to
import the same plugin could seem to be successful.


Modified: trunk/gnue-common/src/apps/plugin.py
===================================================================
--- trunk/gnue-common/src/apps/plugin.py        2004-03-30 22:17:29 UTC (rev 
5582)
+++ trunk/gnue-common/src/apps/plugin.py        2004-03-30 22:50:53 UTC (rev 
5583)
@@ -162,6 +162,15 @@
     raise LoadError, (name, result)
 
 # -----------------------------------------------------------------------------
+# A list of all previously failed modules
+# -----------------------------------------------------------------------------
+
+# This dictionary remembers all previous failure of module imports/inits. That
+# is necessary because module initialization code is only run at first import
+# attempt.
+failed = {}
+
+# -----------------------------------------------------------------------------
 # Find all modules and subpackages in a package
 # -----------------------------------------------------------------------------
 
@@ -192,10 +201,17 @@
 
 def __list (base, identifier):
 
+  global failed
+
+  if failed.has_key (base):
+    # This has already failed in previous attempt
+    return {base: failed [base]}
+
   try:
     m = __import__ (base, None, None, '*')
   except:
-    return {base: sys.exc_info ()}
+    failed [base] = sys.exc_info ()
+    return {base: failed [base]}
 
   if hasattr (m, '__noplugin__'):
     # This is not a plugin, ignore it
@@ -207,7 +223,8 @@
       try:
         m.__initplugin__ ()
       except:
-        return {base: sys.exc_info ()}
+        failed [base] = sys.exc_info ()
+        return {base: failed [base]}
     return {base: m}
 
   # List all submodules
@@ -223,10 +240,17 @@
 
 def __first (base, identifier):
 
+  global failed 
+
+  if failed.has_key (base):
+    # This has already failed in previous attempt
+    return {base: failed [base]}
+
   try:
     m = __import__ (base, None, None, '*')
   except:
-    return {base: sys.exc_info ()}
+    failed [base] = sys.exc_info ()
+    return {base: failed [base]}
 
   if hasattr (m, '__noplugin__'):
     # This is not a plugin, ignore it
@@ -238,7 +262,8 @@
       try:
         m.__initplugin__ ()
       except:
-        return {base: sys.exc_info ()}
+        failed [base] = sys.exc_info ()
+        return {base: failed [base]}
     return m
 
   # Search all submodules
@@ -257,10 +282,15 @@
 
 def __find (base, name, identifier):
 
+  if failed.has_key (base):
+    # This has already failed in previous attempt
+    return {base: failed [base]}
+
   try:
     m = __import__ (base, None, None, '*')
   except:
-    return {base: sys.exc_info ()}
+    failed [base] = sys.exc_info ()
+    return {base: failed [base]}
 
   if hasattr (m, '__noplugin__'):
     # This is not a plugin, ignore it
@@ -271,12 +301,17 @@
     if name in m.__pluginalias__:
       return __first (base, identifier)
 
+  if failed.has_key (base + '.' + name):
+    # This has already failed in previous attempt
+    return {base + '.' + name: failed [base + '.' + name]}
+
   try:
     m = __import__ (base + '.' + name, None, None, '*')
   except ImportError:
     pass
   except:
-    return {base: sys.exc_info ()}
+    failed [base + '.' + name] = sys.exc_info ()
+    return {base + '.' + name: failed [base + '.' + name]}
   else:
     return __first (base + '.' + name, identifier)
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]