Changeset 839fd68 in sasmodels for sasmodels/custom/__init__.py


Ignore:
Timestamp:
Sep 17, 2018 2:33:16 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
91bd550
Parents:
2c12061
Message:

cache modules by timestamp in the custom kernel loader

File:
1 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 
Note: See TracChangeset for help on using the changeset viewer.