[PATCH 14/16] Import collected modules only once

Martin Sivak msivak at redhat.com
Fri Dec 14 10:20:28 UTC 2012


Well when one spoke file imports another while we are doing the directory traversal we could try loading the module again directly without this code (and it happened to me in the new firstboot code as I import quite lot of stuff from anaconda). 

----- Original Message -----
> > diff --git a/pyanaconda/ui/common.py b/pyanaconda/ui/common.py
> > index b1a8dd3..9c3ef8d 100644
> > --- a/pyanaconda/ui/common.py
> > +++ b/pyanaconda/ui/common.py
> > @@ -24,6 +24,7 @@ import os
> >  import imp
> >  import inspect
> >  import copy
> > +import sys
> >  
> >  class PathDict(dict):
> >      """Dictionary class supporting + operator"""
> > @@ -453,10 +454,13 @@ def collect(module_pattern, path, pred):
> >  
> >          mod_info = None
> >          module = None
> > +
> >          try:
> >              imp.acquire_lock()
> >              mod_info = imp.find_module(mod_name, [path])
> > -            module = imp.load_module(module_pattern % mod_name,
> > *mod_info)
> > +            module = sys.modules.get(module_pattern % mod_name)
> > +            if not module:
> > +                module = imp.load_module(module_pattern %
> > mod_name, *mod_info)
> >              imp.release_lock()
> >          except ImportError:
> >              continue
> 
> ACK, but I'm curious under what circumstances you are seeing this,
> and
> if that's bad/dumb behavior that should also be changed.
> 
> - Chris
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 


More information about the anaconda-patches mailing list