Changeset 839fd68 in sasmodels


Ignore:
Timestamp:
Sep 17, 2018 2:33:16 PM (5 weeks ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, beta_approx, cuda-test, py3, ticket-1074-gammainc, ticket-1142-plugin-reload, ticket-1155BE_PolyElectrolyte, ticket-1157
Children:
91bd550
Parents:
2c12061
Message:

cache modules by timestamp in the custom kernel loader

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/custom/__init__.py

    r0f48f1e r839fd68  
    3737        return module 
    3838 
     39_MODULE_CACHE = {} 
    3940def load_custom_kernel_module(path): 
    4041    """load SAS kernel from *path* as *sasmodels.custom.modelname*""" 
    4142    # Pull off the last .ext if it exists; there may be others 
    4243    name = basename(splitext(path)[0]) 
    43     # Placing the model in the 'sasmodels.custom' name space. 
    44     kernel_module = load_module_from_path('sasmodels.custom.'+name, 
    45                                           os.path.expanduser(path)) 
    46     return kernel_module 
     44    path = os.path.expanduser(path) 
     45    timestamp = os.path.getmtime(path) 
     46    module, cache_time = _MODULE_CACHE.get(path, (None, -1)) 
     47    if cache_time < timestamp: 
     48        # Placing the model in the 'sasmodels.custom' name space. 
     49        module = load_module_from_path('sasmodels.custom.'+name, path) 
     50        _MODULE_CACHE[path] = module, timestamp 
     51 
     52    return module 
  • sasmodels/sasview_model.py

    rd533590 r839fd68  
    6262#: set of defined models (standard and custom) 
    6363MODELS = {}  # type: Dict[str, SasviewModelType] 
     64# TODO: remove unused MODEL_BY_PATH cache once sasview no longer references it 
    6465#: custom model {path: model} mapping so we can check timestamps 
    6566MODEL_BY_PATH = {}  # type: Dict[str, SasviewModelType] 
     
    106107    Load a custom model given the model path. 
    107108    """ 
    108     model = MODEL_BY_PATH.get(path, None) 
    109     if model is not None and model.timestamp == getmtime(path): 
    110         #logger.info("Model already loaded %s", path) 
    111         return model 
    112  
    113109    #logger.info("Loading model %s", path) 
    114110    kernel_module = custom.load_custom_kernel_module(path) 
     
    127123        model_info = modelinfo.make_model_info(kernel_module) 
    128124        model = make_model_from_info(model_info) 
    129     model.timestamp = getmtime(path) 
    130125 
    131126    # If a model name already exists and we are loading a different model, 
     
    144139 
    145140    MODELS[model.name] = model 
    146     MODEL_BY_PATH[path] = model 
    147141    return model 
    148142 
Note: See TracChangeset for help on using the changeset viewer.