Exemple #1
0
 def __setstate__(self, state):
     self.__dict__.update(state)
     for module_name, lazy_attributes in state["lazy_modules"]:
         self.__dict__.update(
             {module_name: LazyITKModule(module_name, lazy_attributes)})
     for module in state["loaded_lazy_modules"]:
         namespace = {}
         base.itk_load_swig_module(module, namespace)
         for k, v in namespace.items():
             setattr(self, k, v)
Exemple #2
0
    def _LoadModules(self) -> None:
        """Loads all the module that may have not been loaded by the lazy loading system.

        If multiple modules use the same object, the lazy loading system is only going to
        load the module in which the object belongs. The other modules will be loaded only when necessary.
        """
        name = self.__name__.split("::")[-1]  # Remove 'itk::' or 'itk::Function::'
        modules = base.itk_base_global_lazy_attributes[name]
        for module in modules:
            # find the module's name in sys.modules, or create a new module so named
            swig_module_name = "itk." + module + "Python"
            this_module = sys.modules.setdefault(
                swig_module_name, base.create_itk_module(module)
            )
            namespace = {}
            if not hasattr(this_module, "__templates_loaded"):
                base.itk_load_swig_module(module, namespace)
Exemple #3
0
 def __getattribute__(self, attr):
     value = types.ModuleType.__getattribute__(self, attr)
     if value is not_loaded:
         with _gbl_lazy_load_lock:  # All but one thread will block here.
             if value is not_loaded:
                 # Only the first thread needs to run this code, all other blocked threads skip
                 module = self.__belong_lazy_attributes[attr]
                 namespace = {}
                 base.itk_load_swig_module(module, namespace)
                 self.loaded_lazy_modules.add(module)
                 for k, v in namespace.items():
                     setattr(self, k, v)
                 value = namespace[attr]
             else:  # one of the other threads that had been blocking
                 # waiting for first thread to complete. Now the
                 # attribute is REQUIRED to be available
                 # can just fall through now.
                 value = types.ModuleType.__getattribute__(self, attr)
                 assert value is not not_loaded
     return value